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