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 LongTransactionLogger | |
def transaction(options = {}, &block) | |
start_time = Time.now.to_f | |
rv = super(options, &block) | |
::LongTransactionLogger.log(Time.now.to_f - start_time, self.name, caller(1)) | |
rv | |
end | |
def self.log(duration, model_name, stacktrace) | |
RAILS_DEFAULT_LOGGER.error "LongTransactionLogger (#{model_name}.transaction [#{duration}s]):\n#{stacktrace.join("\n")}" if duration > 5 |
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
# Really hacky script to mark all hoptoad errors as resolved. | |
require 'active_resource' | |
require 'net/http' | |
ACCOUNT="your-account-name" | |
AUTH_TOKEN='your-auth-token' | |
class Hoptoad < ActiveResource::Base | |
self.site = "http://#{ACCOUNT}.hoptoadapp.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
module Behaviour | |
def child_class | |
Child | |
end | |
end | |
module Family | |
class Child; 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
# Full code is at http://github.com/cwninja/rack-cache-buster | |
require 'digest/md5' | |
module Rack | |
class CacheBuster | |
def initialize(app, key, target_time = nil) | |
@app, @target_time = app, target_time | |
@key = "-"+Digest::MD5.hexdigest(key || "blank-key").freeze | |
@key_regexp = /#{@key}/.freeze |
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
height = 10 | |
base = [height / 6, 8].max | |
width = lambda{|r| r * 2 - 1} | |
to_center = lambda{|s| s.center([height, base].map(&width).max)} | |
to_stars = '*'.method(:*) | |
tree = lambda{|v| v.map(&width).map(&to_stars) } | |
puts ( | |
tree[1..height] + | |
tree[[2]*3] + |
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" | |
# Example Usage: | |
# | |
# use Rack::Proxy do |req| | |
# if req.path =~ %r{^/remote/service.php$} | |
# URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}") | |
# 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 "net/http" | |
require "enumerator" | |
# Example Usage: | |
# | |
# use Rack::Proxy do |req| | |
# if req.path =~ %r{^/remote/service.php$} | |
# URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}") | |
# 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
class Rack::ProcTitle | |
F = ::File | |
PROGNAME = F.basename($0) | |
def initialize(app) | |
@app = app | |
@appname = Dir.pwd.split('/').reverse. | |
find { |name| name !~ /^(\d+|current|releases)$/ } || PROGNAME | |
@requests = 0 | |
$0 = "#{PROGNAME} [#{@appname}] init ..." |
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 Rack::Jsmin | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
response, headers, body = @app.call(env) | |
if response == 200 and not env["rack.jsmin.ignore"] and headers["Content-Type"].starts_with? "text/javascript" | |
payload = "" | |
body.each{|part| payload << part} |
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 PerRequestCache #THIS IS TOTALLY NOT THREAD SAFE!!!!!!! | |
class << self | |
def open_the_cache | |
@cache = {} | |
end | |
def clear_the_cache | |
@cache = nil | |
end |