February 2011
2 posts
December 2010
2 posts
July 2010
1 post
June 2010
3 posts
April 2010
2 posts
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.
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
...
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?
...
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...
February 2010
2 posts
October 2009
1 post
July 2009
2 posts
June 2009
2 posts
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...
May 2009
8 posts
1 tag
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
twitter client in MacRuby →
Great post I’ve been using to learn how to fetch stuff off the web asynchronously
1 tag
1 tag
1 tag
1 tag
1 tag
April 2009
3 posts
1 tag