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
# Patch Rack::File to support pre-gzipped files | |
module Rack | |
class File | |
def _call_with_static_gzip(env) | |
@path_info = Utils.unescape(env["PATH_INFO"]) | |
return forbidden if @path_info.include? ".." | |
@path = F.join(@root, @path_info) + '.gz' | |
if F.file?(@path) && F.readable?(@path) | |
serving |
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 'net/http' | |
class Net::HTTP | |
def transport_request_with_retry(req) | |
# First attempt will be after 100ms | |
delay = 0.1 | |
begin | |
transport_request_without_retry(req) | |
rescue Errno::ECONNRESET => e | |
if delay < 4 | |
Kernel.sleep(delay) |
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 'logger' | |
class ColoredLogger < Logger | |
WHITE = "\e[37m" | |
CYAN = "\e[36m" | |
MAGENTA = "\e[35m" | |
BLUE = "\e[34m" | |
YELLOW = "\e[33m" | |
GREEN = "\e[32m" | |
RED = "\e[31m" | |
BLACK = "\e[30m" |
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
# Temporary extension. This will be merged into Tire eventually. | |
module RestClient | |
def self.delete_with_payload(url, payload, headers={}, &block) | |
Request.execute(:method => :delete, :url => url, :payload => payload, :headers => headers, &block) | |
end | |
end | |
module Tire | |
module HTTP |
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 'faraday' | |
module StatHat | |
module API | |
extend self | |
CLASSIC_VALUE_URL = "http://api.stathat.com/v".freeze | |
CLASSIC_COUNT_URL = "http://api.stathat.com/c".freeze | |
EZ_URL = "http://api.stathat.com/ez".freeze | |
def post_value(stat_key, user_key, value) |
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 'timeout' | |
module Rack | |
class Timeout | |
def initialize(app, timeout = 5) | |
@app, @timeout = app, timeout | |
end | |
def call(env) | |
::Timeout.timeout(@timeout, ::Timeout::Error) { @app.call(env) } | |
rescue ::Timeout::Error |
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
--- ext/openssl/extconf.rb.orig 2012-09-11 13:32:19.000000000 +0400 | |
+++ ext/openssl/extconf.rb 2012-09-11 13:32:37.000000000 +0400 | |
@@ -115,6 +115,7 @@ | |
have_func("ENGINE_get_digest") | |
have_func("ENGINE_get_cipher") | |
have_func("ENGINE_cleanup") | |
+ have_func("ENGINE_load_dynamic") | |
have_func("ENGINE_load_4758cca") | |
have_func("ENGINE_load_aep") | |
have_func("ENGINE_load_atalla") |
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 'faraday' | |
require 'zlib' | |
module FaradayMiddleware | |
class Gzip < Faraday::Response::Middleware | |
def on_complete(env) | |
encoding = env[:response_headers]['content-encoding'].to_s.downcase | |
case encoding | |
when 'gzip' |
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 'zlib' | |
module Mongoid | |
module Fields | |
module Compressed | |
extend ActiveSupport::Concern | |
class Field | |
include Mongoid::Fields::Serializable |
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 DrawTree | |
require 'RMagick' | |
def drawdendrogram(tree, labels={}, file='tree.jpg') | |
h = tree.width * 20 | |
w = 1200 | |
scaling = (w-150).to_f / tree.depth | |
canvas = Magick::Image.new(w, h) | |
draw = Magick::Draw.new | |
draw.line(0,h/2,10,h/2) |
OlderNewer