Skip to content

Instantly share code, notes, and snippets.

@benders
benders / create-database-system.sh
Created September 11, 2012 22:38
Cobbler provisioning helpers
#!/bin/bash
if [ $# -ne 5 ]; then
prog=`basename $0`
echo "Usage $prog <short-hostname> <eth0> <eth1> <eth2> <eth3>" >&2
exit -1
fi
set -xe
@benders
benders / README
Created July 4, 2012 01:17
Using Vagrant and puppet-rbenv
yourproject/
- Vagrantfile
- manifests/
- centos62-64.pp
- modules/
- rbenv/ <-- git submodule of https://github.com/alup/puppet-rbenv
@benders
benders / slice_guard.rb
Created January 4, 2012 03:11
Prevent accidentally calling #[] on a number
# Prevent accidentally calling #[] on a number, we don't bit-slice in this house
[Fixnum, Bignum].each do |k|
k.class_eval do
def [](*args)
raise NoMethodError, "Calling #[] on numbers is wrong. Don't do it."
end
end
end
@benders
benders / nrsysmond.cfg
Created November 8, 2011 19:06
Simple New Relic server monitoring manifest for Puppet
#
# New Relic Server Monitor configuration file.
#
# Lines that begin with a # are comment lines and are ignored by the server
# monitor. For those options that have command line equivalents, if the
# option is specified on the command line it will over-ride any value set
# in this file.
#
#
@benders
benders / subrequest_helper.rb
Created May 19, 2011 18:45
Make sub-requests in Rails 2.3
# PH'NGLUI MGLW'NAFH!
# IA IA IA!
module SubrequestHelper
def get_subrequest_for_uri( uri )
sub_env = request.env.dup
sub_env['REQUEST_URI'] = uri
sub_env['REQUEST_METHOD'] = 'GET'
sub_env['rack.input'] = StringIO.new("")
sub_env.delete('QUERY_STRING')
sub_env.delete_if { |k,v| k =~ /^action_controller/ }
@benders
benders / delayed_job_helper.rb
Created May 10, 2011 05:59
Helper for testing applications using DelayedJob
require 'delayed_job'
module DelayedJobHelper
def self.included(klass)
klass.class_eval <<-RUBY
extend ClassMethods
RUBY
end
module ClassMethods
@benders
benders / routes.rb
Created March 16, 2011 23:38
Hack to define helper named routes in Rails 2.3
ActionController::Routing::Routes.draw do |map|
...
end
module CustomRoutes
protected
def incident_url( record, options = {} )
account_application_alert_url(record.account_id, record.application_id, record.id, options)
end
@benders
benders / test-gc.rb
Created January 20, 2011 21:16
Rake task to set GC params before running tests
We couldn’t find that file to show.
development:
strategy: oauth
oauth_consumer_key: YOUR_KEY_HERE
oauth_consumer_secret: YOUR_SECRET_HERE
base_url: "https://twitter.com"
authorize_path: "/oauth/authenticate"
api_timeout: 10
remember_for: 14 # days
oauth_callback: "http://localhost:3000/oauth_callback"
test:
@benders
benders / script-with-bundler.rb
Created July 2, 2010 20:51
How to use Bundler for a script run via symlink
#!/usr/bin/env ruby
# Bundler needs to find the Gemfile in the current directory, so we
# need to dereference symlinks, then chdir to where this script lives
this_file = __FILE__
while( File.symlink?(this_file) )
this_file = File.readlink(this_file)
end
Dir.chdir(File.dirname(this_file))