Thursday, August 27, 2009

autotest and rails 2.x => NOP

One of the recent rails upgrades killed off autotest for me. My next door neighbor in training at RubyConf suggested the autotest-rails gem. It did the trick and got me running again.

Sunday, August 23, 2009

imgur - Totally simple image hosting

Go to imgur

Choose an image to upload and press 'Continue'

Once uploaded, have links to the original image plus small and large thumbnails. Choose the size you want and copy the proper text for your type of link to paste somewhere.

How simple can it be?

Images are kept for three months after last viewing.

Sunday, August 2, 2009

Necessary bits to make Control.Tabs work

When making Control.Tabs ( http://livepipe.net/control/tabs ) work, it is necessary to put the "new Control.tabs('classname');" javascript at the bottom of the page. The header just doesn't cut it.

Turn off auto-dating for ActiveRecord in tests

Fixtures have one nice characteristic. setting updated_at and created_at in them overrides what ActiveRecord would normally record. When using Factories (like factory_girl), want to have a way to turn the auto-dating off and on.

Michał Szajbe at Code Tunes provides this useful tidbit.

Add a small bit of code to test_helper.rb inside TestCase
  def without_timestamping_of(*klasses)
if block_given?
klasses.delete_if { |klass| !klass.record_timestamps }
klasses.each { |klass| klass.record_timestamps = false }
begin
yield
ensure
klasses.each { |klass| klass.record_timestamps = true }
end
end
end
After that, just wrap Factory calls in without_timestamping_of to turn off dating.
  without_timestamping_of Article, Comment, User do
Factory(:article, :created_at => 1.week.ago, :updated_at => 1.week.ago)
Factory(:comment, :created_at => 1.day.ago)
Factory(:user, :updated_at => 5.hours.ago)
end
Simple and very useful. Many thanks again to Michał Szajbe at Code Tunes

How to tell if a ruby variable is already set.

Use the 'defined?' command to determine if a variable has already been set in a ruby script.

e.g. alpha = 'A' unless (defined?(alpha))

set the value of alpha to be 'A' unless it's already set. Yes, there are other shorter ways to do this particular. But, the example is still relevant.