Skip to content

Instantly share code, notes, and snippets.

View bsiggelkow's full-sized avatar

Bill Siggelkow bsiggelkow

  • Atlanta, Georgia, USA
View GitHub Profile
@bsiggelkow
bsiggelkow / gist:1723881
Created February 2, 2012 15:07
Find out where a method is defined from
[1,2].method(:many?).source_location
@bsiggelkow
bsiggelkow / jsonify_sinatra.rb
Created January 26, 2012 12:33
Using Jsonify with Sinatra
require 'sinatra/base'
require 'jsonify/tilt'
class JsonifySinatra < Sinatra::Base
helpers do
def jsonify(*args) render(:jsonify, *args) end
end
get '/' do
jsonify :index
@bsiggelkow
bsiggelkow / gist:1191585
Created September 3, 2011 18:32
Jsonify array handling
class Child
attr_accessor :id
def initialize(id)
@id = id
end
end
kids = [Child.new(2), Child.new(4)]
results = [{:id=>3,:kids => kids}]
@bsiggelkow
bsiggelkow / sanitizer.rb
Created January 31, 2011 19:43
Avoid hidden bugs by turning Rails3 mass-assignment warning into an error.
module ActiveModel
module MassAssignmentSecurity
module Sanitizer
protected
def warn!(attrs)
raise "ERROR: Can't mass-assign protected attributes: #{attrs.join(', ')}"
end
end
end
end
p=Harmony::Page.new(<<-HTML
<html><head><title>T</title></head><body></body></html>
HTML
)
p.execute_js("document.write('foo')")
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new(:webrat) do |t|
t.fork = true # Explicitly fork for cucumber 0.3.4 and rails
t.cucumber_opts = "--format progress"
t.step_list = %w{features/support/env.rb features/support/webrat.rb features/step_definitions}
t.feature_list = %w{features/webrat}
end
task :webrat => 'db:test:prepare'
class SearchResult
attr_reader :title, :abstract, :click_url, :display_url, :date
def initialize(result)
@title = result.title
@abstract = result.abstract
@click_url = result.clickurl
@display_url = result.dispurl
@date = result.date
end