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 |
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
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
# async_sinatra_example.ru | |
require 'sinatra' | |
# Normally Sinatra::Base expects that the completion of a request is | |
# determined by the block exiting, and returning a value for the body. | |
# | |
# In an async environment, we want to tell the webserver that we're not going | |
# to provide a response now, but some time in the future. | |
# | |
# The a* methods provide a method for doing this, by informing the server of |
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
# I stole this code from em-mysql (tmm1 <3) | |
module Sequel | |
class Database | |
attr_accessor :_async | |
end | |
class Dataset | |
def async_insert *args, &cb | |
db._async.insert insert_sql(*args), &cb | |
nil |
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 'sinatra/metal' | |
class SinatraMetal < Sinatra::Base | |
include Sinatra::Metal | |
get '/sinatra' do | |
'hello sinatra!' | |
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
#!/usr/bin/env ruby | |
require "benchmark" | |
bit64 = 1.size == 8 | |
open('gdb-script', 'w') do |f| | |
f.puts <<-EOS | |
p ((unsigned int)rb_gc_stack_start - (unsigned int)$#{bit64 ? 'r' : 'e'}sp) | |
detach |
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 'thread' | |
module EventMachine | |
module Test | |
module Utils | |
module Cranking | |
# Stolen from MenTaLguYs Omnibus | |
class Waiter | |
def initialize |
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
module Enumerable | |
def return | |
each do |i| | |
value = yield(i) | |
return value if value | |
end | |
nil | |
end | |
end |
OlderNewer