This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
require 'kconv' | |
class BBSTerm < EM::Connection | |
def post_init | |
@read_buffer = "" | |
@initialization = true | |
end | |
def receive_data(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def return | |
each do |i| | |
value = yield(i) | |
return value if value | |
end | |
nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
class Hash | |
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second. | |
def reverse_merge(other_hash) | |
other_hash.merge(self) | |
end | |
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second. | |
# Modifies the receiver in place. | |
def reverse_merge!(other_hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FiberedMutex | |
# | |
# Creates a new FiberedMutex | |
# | |
def initialize | |
@waiting = [] | |
@locked = false | |
end | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rackup | |
require 'forward' | |
run Rack::Forwarder.new('google.com') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env thin -e production -R config.ru -V start | |
# config.ru | |
# N.B. Rack::Lint doesn't yet support the api, use production mode rack. | |
require 'eventmachine' | |
class AsyncApp | |
class DeferrableBody | |
include EventMachine::Deferrable |