Skip to content

Instantly share code, notes, and snippets.

View jelder's full-sized avatar

Jacob Elder jelder

View GitHub Profile
@jelder
jelder / param-hash.rb
Created April 3, 2011 17:18
Shortcut for manipulating HTTP request parameters
class ParamHash < HashWithIndifferentAccess
def merge_string!(string)
hash = Hash.new
string.split('&').each { |kv|
k,v = kv.split('=')
hash[k] = URI::unescape(v)
}
self.merge! hash
end
def merge_string(string)
( sudo crontab -l ; echo '@daily rm -rf /private/var/log/asl/*.asl') | sudo crontab
@jelder
jelder / myjob.rb
Created September 19, 2011 15:25
Minimal DelayedJob template with errors captured by NewRelic RPM
require 'newrelic_rpm'
class MyJob
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
def perform
begin
[][0][] # Just here to raise NoMethodError
rescue StandardError => e
NewRelic::Agent.notice_error e
raise e
end
@jelder
jelder / .vimrc
Created November 29, 2011 17:07
My .vimrc
" This is jelder's .vimrc. Use it well.
syntax on
filetype on
filetype indent on
filetype plugin on
set cinoptions=:0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set formatoptions=tcqr
@jelder
jelder / ChromeFullscreen.applescript
Created December 9, 2011 22:24
AppleScript to launch Chrome in Presentation mode (Fullscreen)
# url.txt should contain the URL load in Chrome in full screen.
do shell script "open '/Applications/Google Chrome.app' " & readFile("/url.txt")
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "f" using {command down, shift down}
end tell
# All this just to read a file; no backticks in AppleScript.
on readFile(unixPath)
@jelder
jelder / 404.html
Created March 2, 2012 17:56
A 404 page for Octopress blogs which have been migrated from Blogger and may have broken inbound links (.html -> /)
---
layout: page
title: "Not Found"
sharing: false
footer: false
---
Sorry, that page doesn't exist. <span id="suggestion"/>
<script type="text/javascript">
#!/usr/bin/ruby
class Node
attr_accessor :val, :left, :right
def initialize( val = nil )
@val = val
@left, @right = nil, nil
end
@jelder
jelder / gist:2154989
Created March 22, 2012 01:19
New Machine Checklist
@jelder
jelder / install_ruby.sh
Created May 25, 2012 02:22
Get the specificed version of Ruby onto a Linux host by any means necessary, and cache it in S3.
#!/bin/bash
# Get the specificed version of Ruby onto a Linux host by any means necessary. Invoke like this:
#
# curl https://raw.github.com/gist/2785410/install_ruby.sh | bash -s -- -r '1.9.3-p125' -b mybucket
#
# Jacob Elder <jacob@boundless.com>
usage() {
echo "Usage: $(basename $0) -r 1.9.3-p125 -b mybucket"
exit 1
@jelder
jelder / backup.sh
Created June 19, 2012 21:24
Backup not-normally-tangibile Chef objects into a Git repo.
#!/bin/bash
# Roles, environments, etc only need to exist in the Chef server, which means
# they never hit version control without human intervention (or this script).
for data_bag in $(knife data bag list) ; do
for item in $(knife data bag show $data_bag) ; do
mkdir -p $path data_bags/$data_bag
knife data bag show $data_bag $item -Fj > data_bags/$data_bag/$item.json
git add data_bags/$data_bag/$item.json
done