November 2009
1 post
3 tags
Solving the problem of non-working key forwarding...
After I upgraded my Mac to Snow Leopard, Capistrano deployments with key forwarding stopped working. I started getting a following error: Permission denied (publickey). My fellow Bambinos enlightened me that key forwarding was switched off by default in Snow Leopard. The solution was to change the following two lines in /etc/ssh_config: #Host * #ForwardAgent no to the following two...
Nov 1st
July 2009
1 post
migration to generate paperclip attachment on your...
./script/generate paperclip MODEL_NAME ATTACHMENT_NAME example: ./script/generate paperclip video source GENERATES: add_attachments_source_to_video.rb class AddAttachmentsSourceToVideo < ActiveRecord::Migration def self.up add_column :video, :source_file_name, :string add_column :video, :source_content_type, :string add_column :video, :source_file_size, :integer end def self.down ...
Jul 6th
June 2009
2 posts
Jun 19th
1 note
Is beanstalkd really distributed?
I recently needed to understand how beanstalkd works and how does it implement the distributed behaviour, so I did some reading. From the beanstalkd main page: beanstalkd is a fast, distributed, in-memory workqueue service Ok, it is a distributed service, so let’s find some more info about its distributed nature. This is what we can find in beanstalkd FAQ: Does beanstalk inherently...
Jun 7th
1 note
May 2009
2 posts
Run Apple's QuickTime Player from the terminal
open -a “QuickTime Player” VIDEO_FILE
May 16th
Grep in Project command for TextMate →
May 15th
April 2009
1 post
Escaping Params Containing Periods in Ruby on... →
:requirements => { :id => /.*/ }
Apr 3rd
March 2009
3 posts
How to run the Haml plugin generator in Rails...
Here is how to run Haml’s unorthodox plugin generator method using Rails Templates: Here is a sample Rails Template for fun:
Mar 26th
The best UNIX commands on the web →
Mar 26th
4 notes
Freudian slip during copywriting
The alternative, and traditional method of ruinning software projects is called “waterfall”
Mar 11th
February 2009
1 post
Open Terminal Here in Finder →
Feb 25th
January 2009
3 posts
Include custom actions from a module in a Merb...
module Foo def self.included(base) base.show_action(:custom_action) end def custom_action "foo" end end
Jan 23rd
4 notes
Git SHA1 of HEAD in your Rails/Merb App →
Jan 19th
4 notes
Delete all removed files from git
git add -u This deletes all removed files from git.
Jan 16th
1 note
December 2008
1 post
Skinny controllers with resources_controller and...
resources_controller takes you a long way into simplifying your controllers. Still, whenever you need to add custom collection or member routes to your app you’re out in the wild again. This snippet of code uses a combination of ActiveRecord’s named_scopes and resources_controller to simplify those custom actions. With a bit more of abtraction it could be turned into library code that...
Dec 8th
1 note
November 2008
9 posts
Convention for ActiveRecord extensions
There’s not one but many ways of extending ActiveRecord. Some people do: ActiveRecord::Base.send :include SomeModule Which in turns includes or extends other modules. Others extend first, and include internally. Others class_eval the hell out of everything. There are a few gotchas to avoid, such as accidentally reloading the same modules (ie. in background tasks), which can cause havoc...
Nov 25th
Get the current working directory of a process
pwdx PID
Nov 19th
Build a bug tracker in 5 mins
Go to google docs, click new spread sheet Click form, create your form with title, description, severity (1 minor .. 5 epic fail), who’s responsible in a dropdown and reported by. Save your form Add conditional colouring on severity Add a completed/status column Embed form onto a page/email form to bug hunters.
Nov 18th
4 notes
Nov 15th
Adding comments to Tumblr →
Nov 12th
2 tags
Special characters in Rails nested routes. →
I hit this problem, and this was the only place, where I could find solution.
Nov 12th
3 tags
ActiveRecord.connection.execute and INSERT...
Today I was working with a more complex version of the following code using ActiveRecord: def find_or_create_user_by_id(id) begin user = User.find(id) rescue User.connection.execute("INSERT INTO users (id ) VALUES(#{id})") user = User.find(id) end return user ...
Nov 12th
3 tags
How to get remote_ip address in Rails application...
To get the ip address of a client in rails application, you can call remote_ip method on request object. This works fine, unless your application is behind proxy which ip address doesn’t match the following regular expression: /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./ If the proxy ip address is different, remote_ip will return ip address of the...
Nov 11th
Test ActiveRecord schemas
I’m writing a gemified extension to ActiveRecord. I want a SQLite database to create a quick and dirty schema to test my finders. Yes, I’m lazy and can’t be bothered to write mocks. I want to be able to add or remove columns quickly while avoiding SQL (did I mention I’m lazy?) Solution: create a SQLite file in your test folder, and the following rake task in your...
Nov 4th
October 2008
2 posts
Deleting Duplicates with Unique Keys in MySQL with...
Trying to delete duplicate data is a pain. Especially when your table is bigger than your RAM available so you cannot just create a temp table can copy the unique rows back and forth. So I’ve made available some code in this gist which will delete duplicate data, in the case where the ids are unique but the data is duplicated. # USE: delete_dups_for(Comment, :post_id) NB: code is at the...
Oct 30th
1 note
Remote Images and jQuery
I just got bitten by something really nasty, so thought I’d care to share… Symptom On a certain page, we are outputting 10 divs each of which contained a radio button and an image. In Safari, (and it turned out IE), each time I refreshed, only some of those 10 divs were rendered. Sometimes it would be 5, sometimes 8, sometimes none displayed at all - it all seemed to be completely...
Oct 13th
September 2008
9 posts
Regex to detect non-ascii
[^a-zA-Z0-9,()\s.-"'\;+!_\/:*\%\?]
Sep 30th
3 tags
Normalize params
Sometimes we need to make sure there is a key in the params hash, even when it’s not defined in the routes.rb file. Ie. params[:page]. Instead of validating it in separate actions, just make sure it’s there in a before_filter before_filter :normalize_params protected def normalize_params params[:page] ||= 1 # some more normalization if needed end Then you can be confident that it...
Sep 25th
gitx — a nice gitk →
Sep 17th
Equal column height
You have several HTML columns and you want them to be the same height. Problem is, the content is dynamic so you don’t know what the actual height will be. This jQuery bit resolves the highest column and applies it to all columns in the group. ;(function($){ $.fn.equalHeight = function(){ var max_height = 0; $(this).each(function(){ var h = $(this).height(); if(h >...
Sep 16th
Webcams @ the Large Hadron Collider →
Sep 12th
cache + content_for = fail
Tumblr is useless and can’t display text without mangling it. To view this post, go to http://gist.github.com/10444 .
Sep 12th
User agent string history →
Sep 10th
Has the Large Hadron Collider destroyed the world... →
Sep 10th
3 tags
Removing mocha stubs and expectations
The following code removes all the method stubs and expectations created with mocha. require 'mocha/standalone' include Mocha::Standalone mocha_teardown
Sep 2nd
August 2008
26 posts
“My new framework goes one better than Caffeine. It’s called Cocaine…...”
– Rails, Merb vs. Caffeine
Aug 29th
Maruku: a Markdown-superset interpreter →
Markdown implementation with extensions such as support for setting classes (very useful when you need to set the class of a <code> block) Example: some.ruby('code') {:lang=ruby}
Aug 25th
Net::HTTP missing delete -- a reprieve
Earlier today I wrote bambinos: I just got really screwed over by Net::HTTP The docs talk about a nice delete method for sending HTTP DELETE requests, however it turns out that it does not exist >> Net::HTTP.methods.include?("delete") => false I am somewhat annoyed, especially given we asked a third-party to respond to DELETE requests, and now have to figure out a way to send them!...
Aug 22nd
1 note
Net::HTTP missing delete
I just got really screwed over by Net::HTTP The docs talk about a nice delete method for sending HTTP DELETE requests, however it turns out that it does not exist >> Net::HTTP.methods.include?("delete") => false I am somewhat annoyed, especially given we asked a third-party to respond to DELETE requests, and now have to figure out a way to send them! Bad ruby! Bad Net HTTP!
Aug 22nd
1 note
ies4osx →
Run 5.0, 5.5 and 6.0 stand alone on OS X.
Aug 22nd
How to mock Rails view helpers with RSpec
If you want to stub view helper method in some view spec, you can do the following: @controller.template.stub!(:helper_method_name).with(:some_args).and_return("some result")
Aug 22nd
should_receive in rspec stories
In Test 1 I do this SSO::SSO.should_receive(:authorize).with(“foo@bar.com”, “pass”).and_return(“asdf”) So now: SSO::SSO.authorize(“foo@bar.com”, “pass”) -> “asdf” Then in test 2 I do SSO::SSO.should_receive(:authorize).with(“foo@bar.com”, “pass”).and_return(“qwer”) But I still...
Aug 21st
Aug 20th
HHGTTG online →
Aug 20th
What’s special about teams with low technical... →
More Agile 08 notes.
Aug 19th
Predicting Velocity When Team Membership Or Size... →
Aug 19th
Easy Rails recommendations with... →
Aug 16th
APIdock - Ruby, Rails and Rspec Documentation →
A nicely designed site, with versioned documentation for Ruby, Ruby on Rails and RSpec. It also allows for users to signup (with OpenID) and post comments - adding to the documentation for a method. These can then be ‘Thanked’ by other members in the community. Overall, very nicely done.
Aug 14th
git branch profile_editing_feature --track...
Aug 8th
Changes in Ruby 1.9 →
Aug 8th