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
## SCROLL DOWN FOR THE RACE, THE FOLLOWING IS JUST UTILITY FROM COMMONLY USED CODE. | |
# Author:: Mohammad A. Ali (mailto:oldmoe@gmail.com) | |
# Copyright:: Copyright (c) 2008 eSpace, Inc. | |
# License:: Distributes under the same terms as Ruby | |
require 'fiber' | |
class Fiber |
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 ShardedFiber < Thread | |
end | |
class MongoFiber < Thread | |
end | |
class FiberXP < Thread | |
end | |
class FiberUltimateEdition < Thread |
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 EscapeLike | |
# Escape SQL LIKE arguments. N.B. This should be combined with use of the | |
# ESCAPE parameter also. See: | |
# http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html | |
# | |
# pattern = escape_like(params[:pattern]) << '%' | |
# query = where(["name LIKE ? ESCAPE ?", pattern, '\\']) | |
# | |
# By default this method uses MySQLs default escape, backslash. | |
# Unfortunately, this can get exceedingly confusing in output. As soon as |
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
>> begin; raise 'boom'; rescue; end | |
=> nil | |
>> begin; raise 'boom'; rescue => e; end | |
=> #<RuntimeError: boom> |
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' | |
require 'eventmachine' | |
get '/' do | |
stream(:keep_open) do |out| | |
count = 0 | |
timer = EM.add_periodic_timer(1) do | |
out << "<p>ohai</p>\n" | |
count += 1 | |
if count == 10 |
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 'rubygems' | |
require 'mechanize' | |
require 'rack/utils' | |
require 'net/http/persistent' | |
require 'yajl' | |
class PagerDutyApi | |
class ApiError < StandardError | |
attr_reader :request, :response | |
def initialize request, response |
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 A | |
def initialize klass | |
klass.class_eval do | |
def a; end | |
end | |
end | |
new self | |
allocate.a | |
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
def ObjectSpace.preload | |
starting_size = $".size | |
ObjectSpace.each_object do |o| | |
o.respond_to?(:constants) && constants.each { |c| o.const_get(c) } | |
end | |
retry unless $".size == starting_size | |
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
class Uri | |
module Escaping | |
RESERVED = [] | |
%<:/?#[]@!$&'()*+,;=>.each_byte { |b| RESERVED << b } | |
ESCAPE_MAP = Hash.new do |h,k| | |
h[k] = RESERVED.include?(k) ? '%%%02X' % k : k.chr | |
end | |
0.upto(255) { |i| RESERVED[i] } |
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
# CAVEATS: only known to support 1.8.15 and master as of 2012/2/1 | |
if Gem::Specification.respond_to?(:find_by_name) | |
if Gem.respond_to?(:unresolved_deps) | |
def unresolved | |
Gem.unresolved_deps | |
end | |
elsif Gem::Specification.respond_to?(:unresolved_deps) | |
def unresolved | |
Gem::Specification.unresolved_deps |