Skip to content

Instantly share code, notes, and snippets.

var gistPrefix = 'https://gist.github.com/',
// Cache document.write so that it can be restored once all Gists have been
// embedded.
cachedWrite = document.write,
body = $('body'),
// Map each p.gist to an object that contains the paragraph to be replaced
// and the Gist's identifier.
gists = $('a.gist').map(function(n, a) {
a = $(a);
var href = a.attr('href');
@behrends
behrends / tail-recursive.rb
Created August 6, 2011 14:46 — forked from anonymous/tail-recursive.rb
notes on Ruby Tail Call Optimization
# First, I suppose you have ruby 1.9.1 or 1.9.2
# Open irb. Execute this:
# RubyVM::InstructionSequence.compile_option = { tailcall_optimization: true, trace_instruction: false }
# Note, RubyVM::InstructionSequence.compile_option() doesn't have item :trace_instruction, still, you need to specify it. WTF?
# Also, it doesn't work if you just put it to the script. Don't know why yet. Tell me (@rofh) if you know.
# Then open the file:
# require "./tail-recursive"
# Then execute function:
# fact(30000)
@behrends
behrends / gist:1032218
Created June 17, 2011 20:17 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@behrends
behrends / gist:876627
Created March 18, 2011 18:56 — forked from leshill/gist:870866
javascript dialogs in tests
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@behrends
behrends / fragment.rb
Created September 7, 2010 22:02 — forked from tenderlove/fragment.rb
umlauts and encoding in nokogiri
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML::Document.new
doc.encoding = 'UTF-8'
# We added a contextual fragment method for the 1.4.2 release. This *might*
# work in 1.4.1. If you want to mess with 1.4.2, build from my github, or
# grab one of our nightly builds:
#