Monday, August 23, 2010

Setup google analytics to observe your blogger(blogspot) blog

You may want to view the statistics of your blog and there are many providers from which you can see it. But if you are using blogger(blogspot) then you can follow this link to setup google analytics for your blog and see its statistics. I am using it for my blog too and its pretty cool and interesting.

Finding time difference in Ruby

Finding time difference between two dates or times is very simple in ruby. It is just like doing arithmetic subtraction. We can do it for different formats in the following way:

Date
d1 = Date.parse("2010-08-23")
d2 = Date.parse("2010-08-24")
day_diff = (d2 - d1).to_i     # returns number of days

DateTime
dt1 = DateTime.strptime("2009/04/16 19:52:30", "%Y/%m/%d %H:%M:%S").to_time
dt2 = DateTime.strptime("2009/04/17 19:52:30", "%Y/%m/%d %H:%M:%S").to_time
time_diff = dt2-dt1    # returns time difference in seconds

Time
t1 = Time.parse("2010-08-24 01:20:00")
 t2 = Time.parse("2010-08-24 05:20:00")
time_diff =  t2-t1        # returns time difference in seconds

Friday, August 20, 2010

Using MS Access in Rails application

There is no default support to use MS Access database with our Rails applications. Among many solutions while googling, I have found 2 solutions which can be easily used and managed in our projects. These solutions can be found in the following links –
  1. http://blog.behindlogic.com/2007/07/msaccess-for-rails-heres-your-rough.htm
  2. http://rubyonwindows.blogspot.com/2007/06/using-ruby-ado-to-work-with-ms-access.html

Solution one is more preferable than the second one. Using this solution we can do same operations that we do using ActiveRecord.
If you could not use the solution one for your expected result then you can use second solution. But this solution is not that much intuitive. Using this solution, if you want to any operation then you will need to write SQL yourself.