Skip to content

Instantly share code, notes, and snippets.

View raggi's full-sized avatar

James Tucker raggi

View GitHub Profile
@raggi
raggi / output
Created July 21, 2010 23:02
an example of how to do cross-ruby constant and local binding as a cached method
raggi@mbk: ~ % ruby tiltbinding.rb
info: jruby-1.5.1: jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [x86_64-java]
[:pass, A::B, :block]
info: macruby-0.6: MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64]
[:pass, A::B, :block]
# Example of the implementation
class Template
module CompileSite; end
def compile(klass, name, source)
klass.class_eval <<-RUBY
lambda {}.binding.__send__ :eval, <<-RB
def \#{name}(locals)
\#{source}
@raggi
raggi / rspec_assert.rb
Created July 28, 2010 11:07
assert implemented in rspec
# Someone was using a test helper of mine that relies on a simple assert
# method. As this doesn't exist in rspec, I had to make one, but I wanted the
# messages to work, so, it blew up a little.
module Assert
class Matcher
def initialize(object, message = nil)
@object, @message = object, message
end
A = [8, -21, 8, 2].zip(self.inspect.scan(/./)).map { |a,b| (b[0] - a).chr }.join
B = <<-B
011010000111010001110100011100000011101000101111001011110110011101101001011101
000110100001110101011000100010111001100011011011110110110100101111011000100111
001001111001011000010110111001110111011011110110111101100100011100110010111101
101011011010010111010001110100011110010010111101110010011000010111011100101111
011011010110000101110011011101000110010101110010001011110110001001101001011011
10001011110110101101101001011101000111010001111001
B
require %w[6f70656e2d757269].pack('H*')
@raggi
raggi / oldcodes.rb
Created August 19, 2010 21:06
happy whyday
p(%|#{<<-''}|[?\0...-0x0_2]<<% == <<%< ><<%&#{?../ 0.0_0 }&)
A Big Number Divided By Zero
ruby &= { :spirit => :creative }
@raggi
raggi / eventmachine_is_web_scale.rb
Created September 1, 2010 01:34
the secrets of the web scale sauce
require 'eventmachine'
EM.run do
SEKRET_SAUCE = EM.attach(
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w')
)
EM.start_server('0.0.0.0', 80, Module.new do
def post_init; proxy_incoming_to(SEKRET_SAUCE); end
end)
end
@raggi
raggi / bbsterm.rb
Created September 3, 2010 11:26 — forked from erikh/bbsterm.rb
require 'eventmachine'
require 'kconv'
class BBSTerm < EM::Connection
def post_init
@read_buffer = ""
@initialization = true
end
def receive_data(data)
class Proc; alias ending call; end
story = never'ending'
story =-> { never.ending }
never =-> { story.ending }
story === never.ending
@raggi
raggi / _README.md
Created October 16, 2010 02:14
RubyGems master installer
@raggi
raggi / em_chat_channel_server.rb
Created October 17, 2010 17:42
chat server example using EM::Channel pub-sub, with simple tracing for teaching
require 'eventmachine'
require 'socket'
class Client < EM::Connection
include EM::P::LineText2
HELP = "Server - Welcome to ghettochat. Use /nick to set your nick.\n"
def initialize(global_channel)
@global = global_channel