February 2011
2 posts
Feb 22nd
Feb 15th
December 2010
2 posts
Dec 15th
Dec 10th
July 2010
1 post
Jul 19th
June 2010
3 posts
Jun 29th
Jun 28th
Jun 25th
April 2010
2 posts
Apr 30th
Collect for a hash
module Enumerable def hash_map hash = {} self.each {|o| hash.store(*yield(o))} hash end end my_hash = lines.hash_map {|l| l.split /:/} Great suggestion on redit for creating a hash from other objects.
Apr 23rd
March 2010
3 posts
test helper
I added assert_empty to check that an array is empty. But the line number from test helper.rb was the first line of the test helper, not the line in the test. Instead, I wanted to see the actual failure as the first line. Welcome remove_me_from_trace(exception) class Test::Unit::TestCase def assert_empty(*args) begin args.unshift [] assert_equal *args rescue => e ...
Mar 30th
even better rake db:migrate
I normally don’t like hacking rails files directly, but this is the only way I could extend rake db:migrate to support a friendly VERSION. railities/lib/tasks/database.rake on line 111. # was ENV["VERSION"] ? ENV["VERSION"].to_i : nil # looks up version based upon migration files def version_num version=ENV["VERSION"] if version.to_i==0 && version.present? ...
Mar 24th
better rake db:migrate
I have been using a schell script so I don’t need to remember the long version number associated with ruby migrations. #given a migration task, return the version #e.g.: rake db:migrate:redo VERSION=$(mver create_photo) function mver() { scr=${1:?Please specify migration action} ls db/migrate/*${scr}* | sed 's=^[^0-9]*\([0-9][^_]*\)_.*$=\1=' } which will run migration...
Mar 23rd
February 2010
2 posts
Feb 24th
Feb 20th
October 2009
1 post
Oct 10th
July 2009
2 posts
Jul 10th
Jul 9th
June 2009
2 posts
Jun 25th
1 tag
redirect app
I currently work on port 80, but coworkers work on port 3000. So the urls they send often do not work. I created an app that bounces all local 3000 requests to port 80. mkdir -p bounce/public bounce/tmp cd bounce created config.ru: app = proc do |env| url="http://#{env['SERVER_NAME']}#{env['REQUEST_URI']}" return [302, { "Content-Type" => "text/html", "Location" => url }, "try...
Jun 18th
May 2009
8 posts
1 tag
May 7th
HotConsole (MacRuby irb gui) →
(my fork of Vincent’s work) For me, this is where I started. This is where I rip a lot of my code or at least get the inspiration
May 6th
twitter client in MacRuby →
Great post I’ve been using to learn how to fetch stuff off the web asynchronously
May 6th
1 tag
May 5th
May 4th
1 tag
May 4th
1 tag
May 3rd
1 tag
May 2nd
1 tag
May 1st
April 2009
3 posts
1 tag
Apr 30th
Apr 29th