Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Karmani tmm1

View GitHub Profile
require 'rubygems'
require 'sequel'
require 'mysqlplus'
class Mysql
unless method_defined? :sync_query
alias :sync_query :query
alias :query :async_query
end
end
@tmm1
tmm1 / gist:8461
Created September 2, 2008 20:42
Patch for MRI to disable thread timer (and improve performance) when no threads are running
--- eval.c.orig 2008-08-03 20:24:26.000000000 -0700
+++ eval.c 2008-09-02 14:03:15.000000000 -0700
@@ -10761,6 +10761,8 @@
#endif
}
+static int thread_init;
+
static void
rb_thread_restore_context(th, exit)
@tmm1
tmm1 / gist:9008
Created September 5, 2008 19:40
EM::Timer#reset and #postpone (don't use these, they leak memory)
require 'rubygems'
require 'eventmachine'
class EventMachine::Timer
def reset seconds
prev = EM.instance_variable_get('@timers')[@signature]
cancel
initialize(seconds){ prev.call }
end
require 'rubygems'
require 'eventmachine'
GC.disable
def Object.finalizer info = nil
proc{
p [Time.now, :FINALIZER, info]
}
end
require 'rubygems'
require 'eventmachine'
GC.disable
class Test
Instances = {}
def initialize name
@name = name
Instances[name] = self
diff --git a/gc.c b/gc.c
index 45facf0..a246ce9 100644
--- a/gc.c
+++ b/gc.c
@@ -74,7 +74,12 @@ static unsigned long malloc_increase = 0;
static unsigned long malloc_limit = GC_MALLOC_LIMIT;
static void run_final();
static VALUE nomem_error;
+#ifdef DEBUG_REACHABILITY
+static VALUE garbage_collect0 _((VALUE));
@tmm1
tmm1 / em_proxy.rb
Created October 18, 2008 02:08
simple EM TCP proxy
require 'rubygems'
require 'eventmachine'
Port = (ARGV[0] && ARGV[0].to_i) || 4567
Host = ARGV[1] || '10.0.2.4'
p ['starting proxy', Host, Port]
EM.run{
class String
def space_case
gsub(/([a-z]|[A-Z]+)([A-Z])/){ "#{$1} #{$2}" }
end
def snake_case
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
end
end
class Graph
@tmm1
tmm1 / client.rb
Created October 31, 2008 21:21 — forked from bmizerany/client.rb
require 'rubygems'
require 'eventmachine'
module TapsClient
def connection_completed
p [Time.now, :connected]
send_data("hey!")
end
def receive_data(data)
diff --git a/eval.c b/eval.c
index a238472..2a3baea 100644
--- a/eval.c
+++ b/eval.c
@@ -13617,6 +13604,19 @@ rb_fiber_current()
return th->fiber;
}
+static VALUE
+make_passing_arg(int argc, VALUE *argv)