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
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do | |
def current_connection_id | |
# Thread.current.object_id | |
Thread.main.object_id | |
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
# capture commandline output and send responses if nothing was read | |
def interact(command, answers) | |
puts command | |
line = "" | |
write = false | |
PTY.spawn(command) do |output, input, pid| | |
loop do | |
rs, ws, = IO.select([output], [input]) |
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
gem install pru | |
bundle exec ruby benchmark.rb > report | |
cat report | pru 'split(/\s+/)' 'reject{|a| a.size != 6 }.map{|a| [a[0], a[1]] }.sort_by(&:last).reverse.map{|a| "#{a[0].ljust(21)} -> #{a[1]}" }.join("\n")' | head -n20 | |
haml -> 0.320000 | |
prawn -> 0.270000 | |
mail -> 0.240000 | |
webrat -> 0.230000 | |
newrelic_rpm -> 0.210000 |
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
Dir["tmp/*.txt"].each do |ip_file| | |
puts "-" * 50 | |
puts ip_file | |
ip = File.basename(ip_file).sub('.txt','') | |
puts "ip #{ip}" | |
puts "result:" | |
puts `cat #{ip_file} | ruby script/patch_dns #{ip}` | |
raise unless $?.success? | |
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
`rm accounts/*` | |
ips = File.readlines('ips.txt') | |
accounts = File.readlines('accounts.txt') | |
mapping = {} | |
accounts.each_with_index.map do |subdomain, i| | |
ip = ips[i % ips.size].strip | |
mapping[ip] ||= [] | |
mapping[ip] << subdomain.strip |
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 | |
# Complete rake tasks script for bash | |
# Save it somewhere and then add | |
# complete -C path/to/script -o default rake | |
# to your ~/.bashrc | |
# Xavier Shay (http://rhnh.net), combining work from | |
# Francis Hwang ( http://fhwang.net/ ) - http://fhwang.net/rb/rake-complete.rb | |
# Nicholas Seckar <nseckar@gmail.com> - http://www.webtypes.com/2006/03/31/rake-completion-script-that-handles-namespaces | |
# Saimon Moore <saimon@webtypes.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
if Rails::VERSION::MAJOR == 2 | |
ActionController::Base.class_eval do | |
def params_with_nil_fix | |
params = params_without_nil_fix | |
unless params.instance_variable_get(:@nil_fixed) | |
params.instance_variable_set(:@nil_fixed, true) | |
# normal form params cannot include nil/empty hash/empty array, just json/xml | |
deep_munge(params) unless ["application/x-www-form-urlencoded", "multipart/form-data", nil].include?(request.try(:content_type)) | |
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
rails3 = ENV["BUNDLE_GEMFILE"].to_s.include?("rails3") | |
... | |
if rails3 | |
# make bundler use a different cache dir | |
class << Bundler | |
def app_cache | |
root.join("vendor/cache_rails3") | |
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 "dogapi" | |
require "celluloid/autostart" | |
require "singleton" | |
class LazyDog | |
include Celluloid | |
include Singleton | |
def emit_point(*args) | |
client.emit_point(*args) |
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 audit(klass, method) | |
klass.class_eval do | |
define_method :"#{method}_with_audit" do |*args| | |
result = nil | |
time = Benchmark.realtime do | |
result = send(:"#{method}_without_audit", *args) | |
end | |
$time ||= {} | |
$time[klass] ||= {} | |
$time[klass][method] ||= 0 |