This file contains 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' | |
# 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. | |
# |
This file contains 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 Mogrify | |
class TransformationError < StandardError | |
end | |
def self.from_blob(blob) | |
ImageStream.new(blob) | |
end | |
class ImageStream |
This file contains 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 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') |
This file contains 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
# 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 |
This file contains 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
STDOUT.sync = true | |
require 'queue' | |
start_time = Time.now.to_i | |
msg = 0 | |
queue = Queue.new("testing") | |
queue.subscribe do |obj| | |
msg += 1 |
This file contains 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 'fiber' | |
module Rack | |
class Fabric | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
fib = Fiber.new do |
This file contains 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
def self.accelerated_belongs_to(record) | |
klass = record.to_s.camelize.constantize | |
if !klass.respond_to?(:current) | |
raise ArgumentError, "#{record} does not implement the current class method that is needed for accelerated_belongs_to." | |
end | |
self.belongs_to record | |
alias_method :"#{record}_without_acceleration", record |
This file contains 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
includes = Product.includes_from_params(params) | |
conditions = Product.conditions_from_params(params) | |
@product_count = shop.products.count(:all, :include => includes, :conditions => conditions) | |
@products = shop.products.find(:all, | |
:limit => page_limit, | |
:offset => page_offset, | |
:conditions => conditions, |
This file contains 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
<html> | |
<body> | |
<script> | |
var TestCase = function(testcase) { | |
var success = 0; | |
var failure = 0; |
This file contains 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
[tobi@i7:~]% irb | |
ree-1.8.7-2010.02 > require 'rubygems' | |
=> true | |
ree-1.8.7-2010.02 > require 'json' | |
=> true | |
ree-1.8.7-2010.02 > JSON.parse([ Time.now ].to_json)[0].class | |
=> String | |
ree-1.8.7-2010.02 > require 'json/add/core' | |
=> true | |
ree-1.8.7-2010.02 > JSON.parse([ Time.now ].to_json)[0].class |