This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module A | |
def hi(*list) | |
singleton = class << self; self; end | |
list.each do |l| | |
singleton.send(:define_method, l) do | |
puts l | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
narnach@narnachbook ~/Development $ jruby speed.rb && ruby speed.rb | |
user system total real | |
define_method :one 0.107740 0.003617 0.111357 ( 0.156973) | |
define_method :two 0.075185 0.001356 0.076541 ( 0.098557) | |
def three 0.033372 0.000635 0.034007 ( 0.042528) | |
user system total real | |
define_method :one 0.100000 0.000000 0.100000 ( 0.130217) | |
define_method :two 0.100000 0.000000 0.100000 ( 0.106536) | |
def three 0.050000 0.000000 0.050000 ( 0.045840) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby 1.8.6p111 (from source) vs ruby1.9.1-preview1_0 (macports) vs jruby (nicksieger's github version cc5d6648b27890c25aa50b3ebb8fb10d30b1df1f) | |
narnach@narnachbook ~/Development $ ruby speed.rb && ruby1.9 speed.rb && jruby speed.rb | |
user system total real | |
define_method :one 0.970000 0.000000 0.970000 ( 0.994811) | |
define_method :two 0.990000 0.010000 1.000000 ( 1.000196) | |
def three 0.420000 0.000000 0.420000 ( 0.434437) | |
user system total real | |
define_method :one 0.300000 0.000000 0.300000 ( 0.298044) | |
define_method :two 0.290000 0.000000 0.290000 ( 0.295531) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'active_support' | |
class John | |
end | |
j_c = John.class_eval do | |
def hi | |
'hi' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: s2b.sh branchname | |
# Easily switch between branches and their databases for Rails projects. | |
# Checks out given branch and copies the branch's database.yml to the active database.yml | |
# Outputs a small list of databases being used. | |
# Make sure you have set up your branch's database.yml in #{RAILS_ROOT}/config/database.#{branchname}.yml | |
git checkout $1 && cp config/database.$1.yml config/database.yml | |
databases=`grep --colour=auto database config/database.yml | grep -v ^# | sed s/database\:// | tr -d '\012' | sed -E s/^\ +\|\ +$// | sed -E s/\ +/,\ /g` | |
echo "Using databases: $databases" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Your random BOFH excuse calendar. | |
# Based upon the The Bastard Operator From Hell Stories written by Simon Paul Travaglia. | |
# And the list compiled by Jeff Ballard, http://jeffballard.us/ | |
# | |
# Automatically downloads the excuses from http://pages.cs.wisc.edu/~ballard/bofh/excuses | |
# and stores them as ~/.excuses.txt for reuse. | |
require 'open-uri' | |
class Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "precompile assets (only if needed)" | |
task :precompile_assets do | |
puts "Diffing assets to check if we need to precompile" | |
precompile = true | |
# Only do this if we have a previous release | |
# Do a normal precompile on a force precompile | |
if previous_release && latest_release && !ENV['FORCE_PRECOMPILE'] | |
puts "Comparing asset sources of #{previous_release} and #{latest_release}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Based on https://gist.github.com/choonkeat/4277277 | |
# | |
# Not sure what the deal was with all that SSL stuff in there, but it was the cause content fetching did not work. | |
# Replaced it with plain old open-uri and it just works. | |
require 'net/https' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'json' |