Monday, June 11, 2012

Concat string via MY SQL & PSQL

Hey guys,
      Do you know there is little bit difference to concat the string  under MY SQL & PSQL?

mysql:

update posts set title = concat(title, 'Hey')

psql:

update posts set title = title || 'Hey'


Schedule cron job on linux

Hello Guys,
   Set cron job on linux to invoke at every 1 minute or daily base.

on command prompt:

crontab -e

add below lines

For every 1 minute:

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

For daily

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

Friday, June 8, 2012

rake jobs:work fails - delayed_job

 Hello Guys,
       Do you stuck with the problem to execute rake jobs:work during delayed_job implementation? than follow the below steps.
 Rake.rb
In your rails application's Rakefile add few lines.

begin
  gem 'delayed_job', '~>2.0.5'
  require 'delayed/tasks'
rescue LoadError
  STDERR.puts "rake gems:install` to install delayed_job"
end

Also if you want to use the script/delayed_job start command than add delayed_job under lib folder of rails application.

lib/delayed_job

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '.', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize


Now, you do the rake -T to see that delayed_job task are also embed. Hope you will find useful support via this post.

Wednesday, April 25, 2012

Dygraph fails on IE 8

Hello Guys,
      Just discover the problem while loading dygraph on IE 8. There are possible scenarios for dygraph failure.

case 1. instanceof is not support
           replace instanceof with Object.prototype.toString.call()
           Line 500 of dygraph-utils.js replace
              typeof Node === "object" ? o instanceof Node :
           with
              typeof Node === "object" ? Object.prototype.toString.call(o) === Node :

case 2. canvas can't load

<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<!--[if IE]><script src="excanvas.js"></script><![endif]-->
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="http://mycheckpoint.googlecode.com/svn-history/r95/trunk/dygraphs/excanvas.min.js"></script><![endif]-->


Hope above article will help you.

Thursday, April 19, 2012

Configure mailer with ruby

Hello Rubies,
    As we have to send the mail from rails application for that it requires to set the mailer configuration with rails.

First you have to install the package called 'sendmail'
sudo apt-get install sendmail

Now in environment.rb file of rails application set below code:

ActionMailer::Base.delivery_method = :sendmail

config.action_mailer.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => 'test.com',
  :authentication => :plain,
  :user_name => 'XYZ@gmail.com',
  :password => 'PWD' 
}

Hope this post will help you.

Tuesday, April 17, 2012

Number of days between two dates

Hello Rubies,
    Get the days between two dates using below method of ruby date class.

Lets consider we have date range like
date1 = Date.today.to_date
date2 = 1.year.ago.to_date
no_of_days = date1.mjd - date2.mjd

Hope this simple method of ruby date class will help you out to find days between to dates.

Friday, April 6, 2012

Combination of array element

Hello Guys,
    Want the combination of array elements using ruby? than use the below custom method.

def arr_combine(arr_1, arr_2)
    return arr_1 if arr_2.empty?
    arr_3 = []
    arr_1.each do |e1|
      arr_2.each do |e2|
        arr_3 << [e1, e2].flatten
      end
    end
    return arr_3
  end

eg. we have array like arr = [[1,2], [3,4,5]]
we expect the result as [[1,3],[1,4],[1,5],[2,3],[2,4],[2,5]] than simply invoke the above method by passing each element of given array.
arr_combine(arr[0], arr[1]) gives you required outcome.

Hope this post will help you out.