Skip to content

Instantly share code, notes, and snippets.

View leshill's full-sized avatar
🤠

Les Hill leshill

🤠
View GitHub Profile
def update_main_artist
artist = if rovi_artist
Artist.create(:name => rovi_artist.name)
else
artists.first
end
update_attribute :main_artist_id, artist.id
end
@leshill
leshill / resource_responder.rb
Created August 10, 2011 18:29
Responding to a JSON PUT with either a 200 and the updated JSON or 204 and no body
# The default Responder returns 200, {} for a PUT success.
# Not really happy with that. A 204, nil would be better.
# However, for most resources the result of a PUT is that something changes (updated_at).
# A 200 with the updated resource makes sense in that case.
#
# Not really happy with this first cut.
#
class ResourceResponder < ActionController::Responder
protected
# Fast specs
#
# To run from the command line for my_model in your app:
#
# rspec -Ifast_specs fast_specs/models/my_model
#
require 'rspec'
RSpec.configure do |config|
config.mock_with :rspec
@leshill
leshill / Procfile
Created November 28, 2011 20:01
Unicorn config for cedar stack on Heroku.
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
@leshill
leshill / heroku_auto_scaler.rb
Created November 28, 2011 23:21
HerokuAutoScaler -- drop in, require, and go!
# Scale workers on Heroku automatically as your Resque queue grows.
# Mixin the +Scaling+ module into your models to get the behavior.
#
# class MyModel < ActiveRecord::Base
# extend HerokuAutoScaler::AutoScaling
# end
#
# And configure in an initializer +config/initializers/heroku_workers.rb+:
#
# HerokuAutoScaler.configure do
@leshill
leshill / gist:1477817
Created December 14, 2011 18:23
Bookmark this gist in mobile Safari, edit the bookmark and replace the address with the contents of this gist. Hat tip to http://martinkool.com/post/13629963755/firebug-on-ipad-and-iphone, on my iOS5 phone I see: https://skitch.com/leshill/gtmb6/photo.png
javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"
@leshill
leshill / match_method.rb
Created December 30, 2011 07:13 — forked from avdi/match_method.rb
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else
@leshill
leshill / gist:1684107
Created January 26, 2012 18:10 — forked from justinko/gist:1684051
Methods to aid in testing without loading the Rails environment
def stub_model(model_name)
stub_class model_name, ActiveRecord::Base
end
def stub_class(class_name, super_class = Object)
stub_module class_name, Class.new(super_class)
end
def stub_module(module_name, object = Module.new)
module_name = module_name.to_s.camelize
@leshill
leshill / 0-readme.md
Created February 2, 2012 18:46 — forked from burke/0-readme.md
ruby-1.9.3-p0 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.