Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View raggi's full-sized avatar

James Tucker raggi

View GitHub Profile
@raggi
raggi / config.ru
Created November 19, 2008 03:28 — forked from lifo/gist:26399
#!/usr/bin/env thin -e production -R config.ru -V start
# config.ru
# N.B. Rack::Lint doesn't yet support the api, use production mode rack.
require 'eventmachine'
class AsyncApp
class DeferrableBody
include EventMachine::Deferrable
@raggi
raggi / gist:61367
Created February 10, 2009 12:36 — forked from tmm1/gist:61014
class FiberedMutex
#
# Creates a new FiberedMutex
#
def initialize
@waiting = []
@locked = false
end
#
require "benchmark"
class Hash
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
def reverse_merge(other_hash)
other_hash.merge(self)
end
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
# Modifies the receiver in place.
def reverse_merge!(other_hash)
@raggi
raggi / return.rb
Created June 18, 2009 17:04 — forked from lifo/return.rb
module Enumerable
def return
each do |i|
value = yield(i)
return value if value
end
nil
end
end
# Example of the implementation
class Template
module CompileSite; end
def compile(klass, name, source)
klass.class_eval <<-RUBY
lambda {}.binding.__send__ :eval, <<-RB
def \#{name}(locals)
\#{source}
@raggi
raggi / bbsterm.rb
Created September 3, 2010 11:26 — forked from erikh/bbsterm.rb
require 'eventmachine'
require 'kconv'
class BBSTerm < EM::Connection
def post_init
@read_buffer = ""
@initialization = true
end
def receive_data(data)
#!/usr/bin/env rackup
require 'forward'
run Rack::Forwarder.new('google.com')