Skip to content

Instantly share code, notes, and snippets.

View ryansch's full-sized avatar

Ryan Schlesinger ryansch

View GitHub Profile
class Test
__field_missing: (name) =>
print "method is missing:", name
old = @__base.__index
@__base.__index = (name) =>
old[name] or @__field_missing name
x = Test!
class FakeRedis
new: =>
@called = {}
for m in *{ "set_timeout", "connect", "multi", "sadd", }
@__base[m] = (...) =>
@called[m] = ...
true
@ryansch
ryansch / Capfile
Created December 8, 2010 00:07 — forked from tompata/Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
after 'deploy:finalize_code', 'deploy:web:disable'
after 'deploy:start', 'deploy:web:enable'
namespace :deploy do
ruby_block "rvm use default" do
block do
Chef::Mixin::Command.popen4('bash -l -c "rvm use default && env"') do |p,i,o,e|
o.each_line do |line|
next if line.nil?
line.chomp!
next if line.empty?
env_bits = line.split("=")
ENV[env_bits[0]] = env_bits[1]
@ryansch
ryansch / chef.rb
Created May 3, 2011 21:33 — forked from morgoth/chef.rb
# hack for the chef - we cannot read file in http_request resource
ruby_block "Set attributes for http request for #{database[:name]} #{database[:kind]}" do
block do
request = resources(:http_request => "Create backup record for #{database[:name]} #{database[:kind]}")
request.message({:backup => {:filename => compressed_file_name, :kind => database[:kind], :size => File.size(compressed_file_path)}})
end
end
http_request "Create backup record for #{database[:name]} #{database[:kind]}" do
url "http://some-url/backups"
@gerred
gerred / .irbrc
Created June 17, 2011 18:27
My .irbrc file
if defined?(::Bundler)
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first
if global_gemset
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*")
all_global_gem_paths.each do |p|
gem_path = "#{p}/lib"
$LOAD_PATH << gem_path
end
end
end
@davelyon
davelyon / Guardfile
Created June 21, 2011 18:39
Guardfile
require 'guard/rspec'
extensions = ["Guard::RSpec", "Guard::Schema", "Guard::Routes"]
module ::Guard
class Schema < ::Guard::Guard
def run_on_change(_)
UI.info "Clearing the way"
`rake db:test:prepare`
UI.clear
UI.info "Ready to lead the charge!"
require 'daemon_controller'
require 'socket'
REPO_DIR = '/path/to/repos'
WHITELIST = %w{hostthis}
LISTEN = '1.2.3.4'
PORT = '9418'
PID_FILE = 'git-daemon.pid'
LOG_FILE = 'git-daemon.log'
LOCK_FILE = "#{PID_FILE}.lock"
@developish
developish / duration_spec.rb
Created October 15, 2011 02:55
How to create an isolated ActiveRecord connection for testing without breaking the rest of the suite.
require "active_record"
require "lib/duration"
class Event < ActiveRecord::Base
include Duration
end
describe Duration do
before do
ActiveRecord::Base.establish_connection(
@thbar
thbar / initializer.rb
Created October 26, 2011 20:54
Removing sensitive resque args from airbrake notifications
Resque::Failure::SensitiveAirbrake.configure do |config|
config.api_key = @config['airbrake']['api_key']
config.params_filters << 'my_sensitive_job_arg'
config.secure = @config['airbrake']['secure']
config.proxy_host = @config['airbrake']['proxy_host']
config.proxy_port = @config['airbrake']['proxy_port']
config.host = @config['airbrake']['host']
config.logger = Logger.new(STDOUT)
end