Skip to content

Instantly share code, notes, and snippets.

#!/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
# simple Socket API
module EventMachine
class Socket
class Client < EM::Connection
def initialize socket
@socket = socket
end
attr_accessor :socket
@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'
#
##
# 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
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 ||= ''
require 'rubygems'
require 'eventmachine'
### EM::run takes over the process
# puts 1
# EM.run{
# require 'mycode'
# }
# puts 3 # this will never happen
# 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