Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Gupta Karmani tmm1

View GitHub Profile
require 'rubygems'
require 'mq'
EM.run do
def log(*args)
p args
end
amq = MQ.new
$:.unshift File.dirname(__FILE__) + '/../lib'
require 'mq'
EM.run do
# open a channel on the AMQP connection
channel = MQ.new
# declare a queue on the channel
queue = MQ::Queue.new(channel, 'queue name')
#require 'rubygems'
require 'amqp/lib/mq'
EM.run do
def log(*args)
p args
end
# AMQP.logging = true
require 'thread'
Thread.abort_on_exception = true
require 'rubygems'
require 'eventmachine'
class AsyncTime
def self.now
EM.add_timer(2){ yield(Time.now) }
end
end
@tmm1
tmm1 / fbr.rb
Created August 8, 2008 22:16
Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8) [http://github.com/tmm1/fiber18/tree/master]
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize
require File.dirname(__FILE__) + '/fiber18'
require 'bacon'
class Bacon::Context
unless method_defined? :_it
alias :_it :it
def it *args
_it(*args){ if block_given? then yield; Fiber.yield end }
end
require 'rubygems'
require 'rev'
require 'pp'
class Google < Rev::HttpClient
def self.connect loop = Rev::Loop.default
g = super('google.com')
g.attach(loop) if loop
g
end
def ConstSetter(opts)
(@@__const_setter__modules ||= {})[opts] ||= Module.new do |m|
def m.included c
@@__const_setter__modules.index(self).each do |key, val|
c.const_set(key, val)
end
end
end
end
@tmm1
tmm1 / gist:6716
Created August 22, 2008 01:57
Patch to MRI signal.c to prevent unnecessary sigprocmask syscalls
--- signal.c.orig 2008-08-21 18:42:46.000000000 -0700
+++ signal.c 2008-08-21 18:55:42.000000000 -0700
@@ -23,6 +23,7 @@
#if defined HAVE_SIGPROCMASK || defined HAVE_SIGSETMASK
#define USE_TRAP_MASK 1
+static int restore_signals = 0;
#else
#define USE_TRAP_MASK 0
#endif
@tmm1
tmm1 / gist:7414
Created August 27, 2008 03:13
EM::attach (see github.com/riham/eventmachine and github.com/tmm1/eventmachine/commits/em_detach)
diff --git a/ext/cmain.cpp b/ext/cmain.cpp
index 9890218..c9def4e 100644
--- a/ext/cmain.cpp
+++ b/ext/cmain.cpp
@@ -103,6 +103,32 @@ extern "C" const char *evma_connect_to_unix_server (const char *server)
return EventMachine->ConnectToUnixServer (server);
}
+/**************
+evma_attach_fd