Friday, December 16, 2011

How to resolve jcode (LoadError) with contacts gem in rails 3?

Ruby >= 1.9 doesn't have jcode, a module to handle japanese (EUC/SJIS) strings, as it supports unicode natively.

So you will need to add: require 'jcode' if RUBY_VERSION < '1.9' to your gdata gem found under your .rvm directory somewhere similar to this:

/home/.rvm/gems/ruby-1.9.2-p0@your_gemset_name/gems/gdata-1.1.1/lib/gdata.rb
change line 21 to:
if RUBY_VERSION < '1.9'
  require 'jcode'
  $KCODE = 'UTF8'
end

Thursday, December 8, 2011

Export data to XLS/CSV/TEXT from MySQL

To dump all the records from a table called "users" into the file /home/sapna/users.xls as a XLS file you need to do is.

1) Go to mysql comand prompt using command
mysql -u root -p database_name

2)Then use the following SQL query:
SELECT *
INTO OUTFILE '/home/sapna/users.xls'
FIELDS TERMINATED BY ','
ENCLOSED BY ' " '
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM users;
Note that the directory must be writable by the MySQL database server. 
If it's not, you'll get an error message like this:
Can't create/write to file '/home/sapna/users.xls' (Errcode: 13)
 
To resolve above error, you need to do is
i)sudo gedit /etc/apparmor.d/usr.sbin.mysqld
ii)Add line at last  /home/sapna/* rw, - means read/write permission of folder where you want to write xls file
iii)And then make AppArmor reload the users. 
sudo /etc/init.d/apparmor restart/reload
Also note that it will not overwrite the file if it already exists, 
instead showing this error message:
File '/home/sapna/users.xls' already exists
 

Thursday, December 1, 2011

NGINX server configurations.

1) To find path of nginx.conf file.
locate nginx.conf
It will give you locaiton of nginx file.
/usr/local/nginx/conf/nginx.conf                                                                                       
/usr/local/nginx/conf/nginx.conf.default

2)To set domain name
Edit nginx.conf.default
nano /usr/local/nginx/conf/nginx.conf.default
Change server_name settings

server {
                listen       80;
                server_name  localhost; #instead of localhost set live domain name like abc.com

                access_log  logs/localhost.access.log  main;

                location / {
                    root   html;
                    index  index.html index.htm;
                }
        }
}

3)After making of any changes in nginx.conf file you need to reload it.
/etc/init.d/nginx reload

4)After making any changes of project files on server you need to restart nginx server.
/etc/init.d/nginx restart

5)To kill process of nginx
ps aux | egrep '(PID|nginx)'
and kill the PID

Refer site:http://library.linode.com/web-servers/nginx/configuration/basic

Tuesday, November 29, 2011

Setup project from Heroku and git repository

1) Install gem heroku
gem install heroku

2) Add heroku key
The first time you run the heroku command, you’ll be prompted for your credentials. Your public key will then be automatically uploaded to Heroku.
heroku keys:add
Generating new SSH public key.
Uploading ssh public key /home/sapna/.ssh/id_rsa.pub

3)git clone git@heroku.com:giraffe-dev.git

Tuesday, November 15, 2011

Kill Webrick process running on port 3000 without daemon

root@root:~$ sudo netstat -anp | grep 3000
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      3023/ruby     
root@root:~$ sudo kill -9 3023
root@root:~$ rails s

Wednesday, November 9, 2011

Mysql - How to search for exact word match using REGEXP?

If you are looking to match EXACT words then don't use LIKE keyword.
You could do word boundaries with the following REGEXP. 
SELECT * FROM TABLE WHERE field_name RLIKE "[[:<:]]foo[[:>:]]";
In Ruby code you can use it like
Model.find(:all, :conditions => "field_name RLIKE 'foo.*'")
or
Model.find(:all, :conditions => "field_name REGEXP 'foo.*'")

Thursday, November 3, 2011

Javascript to check uncheck all checkbox in a Table

<a href="#" id="check_<%= id %>" onclick="checkParent('<%= id %>', true); return false;">All</a>

<a href="#" id="uncheck_<%= id %>" onclick="checkParent('<%= id %>', false); return false;" style="display:none;">All</a>

<table id="table_<%= id %>">
  <tr>
    <td>
      <%= check_box_tag "locations[]", location.id, false, :onchange => "validate();" ,:id => "locations", :class => "location" %>
    </td>
  </tr>
</table>

function checkByParent(aId,aChecked) {
   
    var inputs_in_table = document.getElementById("table_"+aId).getElementsByTagName("input");
    for(var i=0; i<inputs_in_table.length; i++)
    {
        if(inputs_in_table[i].type == "checkbox") inputs_in_table[i].checked= aChecked;
    }
    if (aChecked == true)
    {
      document.getElementById("check_"+aId).style.display = "none";
      document.getElementById("uncheck_"+aId).style.display = ""; 
    }
    else if(aChecked == false)
    {
      document.getElementById("check_"+aId).style.display = "";
      document.getElementById("uncheck_"+aId).style.display = "none"; 
    }
  }

Thursday, September 29, 2011

extract urls

I have some content with a list of URLs contained in it.

I am trying to grab all the URLs out and put them in an array.

I have code like:

content = "Sample of URLs: http://www.google.com and http://www.google.com/index.html which I want to grab"

And I am trying to get the end results to be:

['http://www.google.com', 'http://www.google.com/index.html']

Either of two ways you can extracts URLs

1) urls = content.split(/\s+/).find_all { |u| u =~ /^https?:/ }

Or you can grab it by using REGEX

2) urls = content.scan(/(?:http|https):\/\/[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:(?::[0-9]{1,5})?\/[^\s]*)?/ix)

but note that it won't match pure IP-address URLs (like http://127.0.0.1), because of the [a-z]{2,5} for the TLD.

Wednesday, August 24, 2011

Install Skype CallRecorder

Download skype-call-recorder-0.8.tar.gz from http://atdot.ch/scr/download/

Prerequisites
sudo apt-get install cpp
sudo apt-get install qt4-dev-tools
sudo apt-get install libmp3lame-dev
sudo apt-get install libid3-dev
sudo apt-get install libvorbis-dev

Install Make

To install make need to go on path where download file resides.

sapna@sapna-desktop:~$ cd /home/sapna/Downloads/skype-call-recorder-0.8/
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ cmake .
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ make
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ sudo make install

Restart PC or use like below
skype-call-recorder &

Setup OS from fresh install of Ubuntu 10.04

Setup OS from fresh install of 10.04
1. Apply any updates requested by Update Manager
2. Install ssh using Synaptics PackageManager
3. sudo apt-get update
4. sudo apt-get install build-essential libreadline6-dev
5. sudo apt-get install postgresql-server-dev-8.4 postgresql-8.4
6. sudo apt-get install libmagickwand-dev
7. sudo apt-get install git-core curl subversion
8. sudo apt-get install libxslt-dev libxml2-dev
9. bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
10. logout and login
11. rvm install 1.8.7-p330
12. rvm install rubygems 1.3.7
13. rvm use 1.8.7-p330

Gem installation specific for ruby 1.8.7
1. gem install rails -v=2.1.2
2. gem install rodf -v=0.1.8
3. gem install roo -v=1.3.11
4. gem install uuidtools -v=2.1.1
5. gem install RedCloth -v=4.2.7
6. gem install rmagick -v=2.13.1
7. gem install zipruby -v=0.3.6
8. gem install pg -v=0.10.1
9. gem install fastercsv -v=1.5.4
10. gem install linefit -v=0.1.0
11. gem install gruff -v=0.3.6
12. gem install mezza-rubyzip
13. gem uninstall rubyzip
* Don't worry about dependency alert. Resolved by mezza-rubyzip
14. gem install testunitxml
15. gem install nokogiri -v=1.4.4
16. gem install xml-simple -v=1.1.0

Postgresql pg_hba.con
1. sudo pico /etc/postgresql/8.4/main/pg_hba.conf
2. replace ident and md5 with trust
* sudo /etc/init.d/postgresql-8.4 restart
3. psql -U postgres < FISHSOURCE_DUMP.SQL

Password for null GNOME keyring in SVN

This happens because your subversion system is trying to use the gnome-keyring for authentication and you've accidentally deleting your GNome keyring.

> Password for '(null)' GNOME keyring:

A solution suggested to avoid the SVN prompting for a password for a keyring. That is typing command in the terminal.

> rm ~/.gnome2/keyrings/login.keyring

After giving this command in the terminal I could svn up and committed code.Usual username and password for SVN were asked and after entering them, the codes are successfully committed.

Monday, January 3, 2011

Break continues text(WRAP TEXT)

When there is continues text like "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" it disturbs the text format.There are 2 ways to do it
1)Adding newline or break after every 100 characters using Javascript.
2)Wrap text by adding style into div tag

Example of first way
-----------------------------------
<div id="company_expertise">
<%long_string = "MYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertise"%>
<%= hidden_field_tag "hnd_company_expertise", long_string %>
</div>
<script type="text/javascript">

str1 = document.getElementById("hnd_company_expertise").value;
str = str1.replace(/(.{100})/g, "$1\n");
document.getElementById("company_expertise").innerHTML = str;
</script>
Example of second way
-----------------------------------------
<div style="word-wrap: break-word;">
<%= "MYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertise" %>
</div>