Skip to content

Instantly share code, notes, and snippets.


Erik Behrends behrends

View GitHub Profile
View tumblrGists.js
var gistPrefix = '',
// 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 / tail-recursive.rb
Created Aug 6, 2011 — forked from anonymous/tail-recursive.rb
notes on Ruby Tail Call Optimization
View tail-recursive.rb
# 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 / gist:1032218
Created Jun 17, 2011 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
View gist:1032218
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
behrends / gist:876627
Created Mar 18, 2011 — forked from leshill/gist:870866
javascript dialogs in tests
View gist:876627
# Add this to more_web_steps.rb
# Selenium docs: today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
behrends / fragment.rb
Created Sep 7, 2010 — forked from tenderlove/fragment.rb
umlauts and encoding in nokogiri
View fragment.rb
require 'rubygems'
require 'nokogiri'
doc =
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:
You can’t perform that action at this time.