Skip to content

Instantly share code, notes, and snippets.

View colinsurprenant's full-sized avatar

Colin Surprenant colinsurprenant

View GitHub Profile
From bb2a78858cffa7c6937642986e9aca1a4f862c0d Mon Sep 17 00:00:00 2001
From: Ilya Grigorik <ilya@igvita.com>
Date: Thu, 10 Jun 2010 00:46:48 -0400
Subject: [PATCH] async rails3
---
Gemfile | 6 ++++++
app/controllers/widgets_controller.rb | 6 ++++++
app/models/widget.rb | 2 ++
config.ru | 1 +
@colinsurprenant
colinsurprenant / migrators.rb
Created October 19, 2010 14:48
object transformation using migrators with Ruby inject idiom
class SomeMigrator
def migrator
lambda do |some_object|
{:previous_object => some_object}
end
end
end
migrators = [SomeMigrator.new.migrator, SomeMigrator.new.migrator]
original_object = "original object"
@colinsurprenant
colinsurprenant / retryable.rb
Created December 14, 2010 21:43
Retryable Ruby module
module Praized
module Slingshot
module Retryable
# execute retryable code block
# thanks to http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/ fo original idea
# @param [Hash] options retryable options
# @option options [Fixnum] :tries retries to perform, default 1.
# @option options [Exception] :on exception on which a retry will be performed, defaults is Exception, which retries on any Exception.
{
hose_name => [
{
hose: hose_name,
title: 'Atlanta twitter content search',
entries_samples: [1,...],
polls_samples: [1,...],
entries_total : 345211,
polls_total : 44556
},
@colinsurprenant
colinsurprenant / global.rb
Created April 7, 2011 19:13
shared global ruby configuration dsl example
module App
module Global
extend self
def self.configure(&block)
instance_eval(&block)
end
def [](key)
config[key]
#!/usr/bin/env jruby
#
#
require 'rubygems'
require 'spoon'
EXEC = '/tmp/exec.rb'
PID_PATH = '/tmp/exec.pid'
WORK_PATH = '/tmp/'
@colinsurprenant
colinsurprenant / pipe.rb
Created April 13, 2011 17:17
ruby unix style pipe/filter example
require 'rubygems'
require 'benchmark'
line_count = 0
elapsed = Benchmark.realtime do
while (line = $stdin.gets)
puts(line)
line_count += 1
end
@colinsurprenant
colinsurprenant / multipart.rb
Created April 13, 2011 21:33
partial multipart message with 0MQ, JRuby and ffi-rzmq
# this is to demonstrate the partial multipart message reception problem.
# in my environment, items will be dropped as expected and also
# partial messages will be received which should not happen per 0MQ
# atomicity semantic.
#
# usage: ruby multipart.rb {pub|sub}
#
# tested using JRuby 1.6.0, 0MQ 2.1.3, ffi-rzmq 0.7.2 on OSX 10.6.7
#
# Colin Surprenant colin.surprenant@gmail.com, http://github.com/colinsurprenant
require 'rubygems'
require 'spoon'
Spoon.spawnp 'jruby', *ARGV
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby