Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
Xzibit = Object clone do(
dawg = method(what,
"yo dawg" print.
what print.
"clone" print.
self
).
so_you_can = method(
"so you can print" print.
require 'rubygems'
require 'eventmachine'
require 'socket'
module RPCServer
include EM::P::ObjectProtocol
def post_init
@obj = Hash.new
end
def receive_object method
#!/usr/bin/env ruby
require "benchmark"
open('gdb-script', 'w') do |f|
f.puts <<-EOS
p ((unsigned int)rb_gc_stack_start - (unsigned int)$esp)
detach
quit
EOS
# Playing with it in irb:
>> (class << Widget; self; end).ancestors
=> [BazWrapper, BarWrapper, FooWrapper, Class, Module, Object, Kernel]
>> widget = Widget.new
=> #<Widget:0x11771f8>
>> (class << widget; self; end).ancestors
=> [BazWrapper::WrappingB, BazWrapper::WrappingA, BarWrapper::Wrapping, FooWrapper::Wrapping,
@deepak
deepak / dup.rb
Created July 19, 2009 10:25
unextend a module | ruby-talk-183401
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/183650
# Have you tried #dup?
module Actor
def work
"actor"
end
end
module Waiter
@deepak
deepak / install_ruby_19.rb
Created July 20, 2009 18:43 — forked from jerodsanto/install_ruby_19.rb
rake task to install ruby
APTGET = "apt-get install -qqy"
RUBY19 = "ruby-1.9.1-p129"
SRC = "/usr/local/src"
WGET = "wget -q"
namespace :ruby do
desc 'download and compile Ruby 1.9'
task :install_19 do
deps = %w'zlib1g-dev libopenssl-ruby1.9'
@deepak
deepak / passenger.rb
Created July 26, 2009 12:49 — forked from tmm1/passenger.rb
copy of the gist - nothing original
# Monkey-patch for Passenger to use the EventMachine reactor.
# This allows the use of EM timers, EM.system/popen, and other async libraries (amqp, em-http-request, etc) inside a Rails process.
# This requires EM.watch which was added to EM's git repo recently. Build an EM gem first:
# git clone git://github.com/eventmachine/eventmachine
# cd eventmachine
# gem build eventmachine.gemspec
# sudo gem install eventmachine-0.12.9.gem
# Please do not use this in production =)
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
Rails CMS alternatives
======================
Note: project activity was checked on 11/26/09.
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
@deepak
deepak / connection_fix.rb
Created March 18, 2010 11:24 — forked from defunkt/connection_fix.rb
fork - to reconnect mysql on stale connection
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/