Skip to content

Instantly share code, notes, and snippets.

@benders
benders / All-Down-503.tcl
Created June 17, 2011 18:58
F5 BigIP iRules
when LB_FAILED {
HTTP::respond 503 content "System down for maintenance" noserver "Connection" "close"
}
@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 / log-rename.sh
Created March 26, 2011 05:31
Rename logs from logrotate style foo.1.gz to date style foo.2011-03-25.gz
#!/bin/bash
ls -l --time-style="+%Y-%m-%d" *.?.gz | awk '{ print $7,$6 }' | \
while read line; do
set -- $line
original=$1
datestamp=$2
filebase=`echo $original | rev | cut -f3- -d. | rev`
/bin/mv -vu $original $filebase.$datestamp.gz
done
@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.
@benders
benders / .gitconfig
Created August 23, 2010 23:50
A Basic .gitconfig file
[user]
name = Your Name
email = username@newrelic.com
[github]
user = github_user_name
token = XXXXXXXXXXXXXXXXXXXXXXXXX
[color]
status = auto
diff = auto
branch = auto
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))
@benders
benders / status_codes.rb
Created May 24, 2010 16:16
File from ActionPack showing HTTP status codes available in Rails
module ActionController
module StatusCodes #:nodoc:
# Defines the standard HTTP status codes, by integer, with their
# corresponding default message texts.
# Source: http://www.iana.org/assignments/http-status-codes
STATUS_CODES = {
100 => "Continue",
101 => "Switching Protocols",
102 => "Processing",