Skip to content

Instantly share code, notes, and snippets.

roidrage /
Created Dec 2, 2011
Self-published and awesome
View timeoutx.rb
#! /usr/bin/env ruby
# you can timeout in ruby even when all signals are blocked by doing the work
# in a child process (relaying the value back up a pipe) and doing the
# timeout-ing in the parent. of course this only works in POSIX systems
require 'timeout'
def timeoutx(seconds, &block)
View a.rb
#! /usr/bin/env ruby
status = DATA.flock(File::LOCK_EX | File::LOCK_NB)
if status == 0
puts "we have the lock..."
igrigorik / webapp.rb
Created Nov 13, 2010
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
View webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
View itr.rb
class Metaclass
include Enumerable
def initialize obj
@obj = obj
def each
return enum_for(:each) unless block_given?
x = meta_for @obj