Skip to content

Instantly share code, notes, and snippets.

# async_sinatra_example.ru
require 'sinatra'
# Normally Sinatra::Base expects that the completion of a request is
# determined by the block exiting, and returning a value for the body.
#
# In an async environment, we want to tell the webserver that we're not going
# to provide a response now, but some time in the future.
#
# The a* methods provide a method for doing this, by informing the server of
require 'rubygems'
require 'eventmachine'
### EM::run takes over the process
# puts 1
# EM.run{
# require 'mycode'
# }
# puts 3 # this will never happen
if __FILE__ == $0
require 'em/spec'
class TestConnection
include EM::P::Memcache
def send_data data
sent_data << data
end
def sent_data
@sent_data ||= ''
##
# sync api: return values and exceptions
begin
images = []
results = RestClient.get('http://google.com/search?q=ruby')
Hpricot(results).find('a').each{ |link|
page = RestClient.get(link)
begin
@aymerick
aymerick / number of durable queues
Created March 19, 2009 12:25
Script to test RabbitMQ's startup time
#!/usr/bin/env ruby
#
# NOTE: You must run this script as root
#
#
# Create a /etc/rabbitmq/rabbitmq.conf file with this content:
#
# MULTI_START_ARGS='
# -maxwait 4800'
#
# simple Socket API
module EventMachine
class Socket
class Client < EM::Connection
def initialize socket
@socket = socket
end
attr_accessor :socket
#!/usr/bin/env ruby
# Seen in god sources (http://god.rubyforge.org)
puts "Calculating stuff"
t = Thread.new { loop { sleep(0.5); STDOUT.print('.'); STDOUT.flush; } }
sleep(5)
t.kill; STDOUT.puts
#
# /my_recipe/librairies/shared.rb
#
class Chef
class Recipe
# Fill an attribute with given hash
def attribute_from_hash(hash)
attribute = Mash.new
class Prout
def initialize(delegate)
@delegate = delegate
end
def delegate
@delegate
end
def method_missing(sym, *args, &blk)
@aymerick
aymerick / fwissr.md
Last active December 30, 2015 06:19
Fwissr introduction blog post

Centralize your configurations

This article introduces Fwissr, our configuration registry tool that we use to centralize all our configurations.

centralize your configuration files

Photo by National Library of Norway

More than five years ago, when we started to build what became fotopedia, we had a main Rails application, a Merb application for user authentication and another Merb application for photo upload. These applications were deployed by Capistrano, and our servers were configured with Puppet with some scripts to glue everything together.