Monday, February 27, 2012

Execute rake file in crontab(RVM)

While executing rake in crontab using rvm, needs to load it properly.

For every 1minute.
 */1 * * * * cd /home/user/application_path && /home/user/.rvm/bin/rvm use ruby-1.9.2-p136 rake reminder_email >> /home/user/crontab_errors.txt


For dayily
0 0 * * * cd /home/user/application_path && /home/user/.rvm/bin/rvm use ruby-1.9.2-p136 rake reminder_email >> /home/user/crontab_errors.txt

Thursday, February 16, 2012

Paperclip 'identify' command error on ubuntu.

The Paperclip.options[:command_path] setting is for the location of your ImageMagick executables (in this case identify).

Try running which identify and setting the option to be the directory that is returned like identify is hashed (/usr/bin/identify).
If that command doesn't return anything, make sure that ImageMagick is properly installed.

If not installed then run following command and install it.

sudo apt-get install imagemagick
sudo apt-get install libmagickwand-dev
gem install rmagick

Then set Paperclip.options[:command_path] = "/usr/bin" in development.rb file

Problem solved.

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