This file contains hidden or 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
# Instances must supply a Klass.load method which is used to load the object | |
# in case it is not available in object space - for example from some data store. | |
# Also objects must provide an id method which is used as the key | |
# | |
module ObjectSpaceIdentityMap | |
def [](id) | |
obj = nil | |
ObjectSpace.each_object(self) do |o| | |
obj = o if o.id == id | |
end |
This file contains hidden or 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
class ExpectContinue | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if env['HTTP_EXPECT'] =~ /\A100-continue\z/i | |
[100, '', {}] | |
else | |
@app.call(env) |
This file contains hidden or 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
require 'rubygems' | |
require 'eventmachine' | |
module EventMachine | |
# This returns a deferrable and catches errors in the block for you. | |
# | |
# Define callbacks and errbacks in usual way instead of weird EM.defer way | |
def self.better_defer?(&block) | |
deferrable = EM::DefaultDeferrable.new |
This file contains hidden or 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
BEANSTALK_13 = '/opt/local/bin/beanstalkd' | |
BEANSTALK_14 = '/usr/local/bin/beanstalkd' | |
n = 100000 | |
require 'rubygems' | |
require 'beanstalk-client' | |
require 'benchmark' | |
def teardown |
This file contains hidden or 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 | |
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and | |
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your | |
# distro. | |
# | |
# Author: Ryan Norbauer <[email protected]> | |
# Modified: Geoffrey Grosenbach http://topfunky.com | |
# Modified: Martyn Loughran http://mloughran.com |
This file contains hidden or 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 IrregularScience | |
def resize_within(w, h) | |
r_old = width.to_f / height | |
r_new = w.to_f / h | |
w_new = r_new > r_old ? (h * r_old).to_i : w | |
h_new = r_new > r_old ? h : (w / r_old).to_i | |
self.resize(w_new, h_new) do |image| | |
yield image |
This file contains hidden or 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
just a test |
NewerOlder