Skip to content

Instantly share code, notes, and snippets.

View tobi's full-sized avatar

Tobias Lütke tobi

View GitHub Profile
require 'fiber'
module Rack
class Fabric
def initialize(app)
@app = app
end
def call(env)
fib = Fiber.new do
STDOUT.sync = true
require 'queue'
start_time = Time.now.to_i
msg = 0
queue = Queue.new("testing")
queue.subscribe do |obj|
msg += 1
# usage: ruby timecard.rb path branch name-of-graph-file-not-including-extension
# e.g.: ruby timecard.rb . master timecard #=> produces timecard.png
require 'rubygems'
# This requires the 'cyberfox-gchart' gem (0.5.4), as the standard
# gchart gem is woefully broken for this kind of graph. Broken to the
# point that it's an inherent design choice that doesn't work well for
# this kind of chart. I'm sure that the cyberfox-gchart gem won't
class JsonHax
def initialize(app)
@app = app
end
def call(env)
if env['CONTENT_TYPE'] == 'application/json'
env['CONTENT_TYPE'] = 'application/xml'
env['REQUEST_URI'].gsub!(/\.json/, '.xml')
module Mogrify
class TransformationError < StandardError
end
def self.from_blob(blob)
ImageStream.new(blob)
end
class ImageStream
@tobi
tobi / em.rb
Created October 10, 2009 21:34
require 'rubygems'
require 'eventmachine'
# I'm writing a micro web framework that works exclusively in an evented environment.
# All IO is wrapped in async calls. The problem is that this leads to very deeply nested actions
# on average. E.g. request comes in -> Memcache query creates a block -> DB query creates a block
# -> next DB query creates a block and so on. This becomes unwieldy. What i'd really like is
# to move the evented stuff into the library and make the implementation for the framework user
# as familar as possible.
#
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
require 'cgi'
class Room < EM::Channel
end
$room = Room.new
$welcome_html = DATA.read
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin os
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin ruby
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin languages
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin kernel
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Plugin kernel threw exception #<NoMethodError: undefined method `fdiv' for 0:Fixnum>
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin ohai_time
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin keys
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin hostname
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Loading plugin linux::hostname
[Fri, 14 Aug 2009 17:20:43 -0400] DEBUG: Plugin linux::hostname threw exception #<NoMethodError: undefined method `fdiv' for 0:Fixnum>
@tobi
tobi / ci
Created August 5, 2009 20:02
output_directory = ARGV[1]
class TestRunner
class Result < Struct.new(:setup, :test_output, :setup_errorcode, :test_errorcode)
end
def initialize(dir)
# ==================
# After login
# getting all blogs for a drop down:
blogs = ShopifyAPI::Blog.find(:all)
blogs.each do |blog|
blog.id #=> 439432
blog.title #=> "My cool blog"