Skip to content

Instantly share code, notes, and snippets.

View fairchild's full-sized avatar

Michael Fairchild fairchild

  • Procore
  • California
View GitHub Profile
@fairchild
fairchild / gist:39271
Created December 23, 2008 06:33
A nice example of Meta programing from the earworm project
{
'ogg' => Audio::OGG::Decoder,
'mp3' => Audio::MPEG::Decoder,
}.each do |type,klass|
define_method(:"decode_#{type}") do |filename|
reader = klass.new
name = File.join(Dir::tmpdir,
"#{File.basename(filename, ".#{type}")}.wav")
File.open(filename, 'rb') { |input|
File.open(name, 'wb') { |tmpfile|
@fairchild
fairchild / gist:44686
Created January 8, 2009 11:15
supporting multiple session with webrat integration tests
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require "webrat"
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
class UserFlowsTest < ActionController::IntegrationTest
include Webrat
bob = test_user_flow do |bob|
bob.visits '/login'
bob.does_something_else'
end
bob.yet_another _thing
sally......
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require "webrat"
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
module MyTestingDSL
def logs_in(login, password)
<div id="player">
<canvas id="levels" width="145" height="24"></canvas>
</div>
def test_create_and_accept
ask = Order.create(:created_by => @sally,
:type => 'Ask',
:shares=>10, :price=>11,
:company=>@company,
:expires => 2.days.from_now,
:purchase_agreement_acceptance => '1',
:proof_of_ownership => '1',
:escrow_acceptance => '1')
assert_equal 4, ask.contracts.count
@fairchild
fairchild / beehive_example.rb
Created February 5, 2009 18:47
ideas for a poolparty configuration
pool :att do
cloud :rails_apps do
using :ec2
instances 2..50
expand_when load > 0.8
expand_when instances > 10 do
load > 0.8 to :slicehost
load > 1.4 to :slicehost
@fairchild
fairchild / object_and_module_grapher.rb
Created February 8, 2009 21:21
graphviz of ruby class heriarchy, modified from http://objectgraph.rubyforge.org/
# jEdit :folding=explicit:collapseFolds=1:indentSize=2:tabSize=2:
# add requires here #{{{
#}}}
# handle command line #{{{
def usage #{{{
puts <<-USAGE
def any_verb(path, block)
get path, &block
post path, &block
put path, &block
delete path, &block
head path, &block
end
any_verb "/" do
"foo"
converse:open_and_send({66,214,143,157}, 8765, {data, whisper:encrypt("hi Ari")}).
Error econnrefused
Error in sending message to {66,214,143,157}:8765: econnrefused
error
3> converse:open_and_send({66,214,143,157}, 8765, {data, whisper:encrypt("hi Ari")}).
Error econnrefused
Error in sending message to {66,214,143,157}:8765: econnrefused
error
4>
=INFO REPORT==== 19-Feb-2009::00:16:05 ===