Skip to content

Instantly share code, notes, and snippets.

View tylerhunt's full-sized avatar

Tyler Hunt tylerhunt

View GitHub Profile
@tylerhunt
tylerhunt / gist:206213
Created October 9, 2009 18:03
Rack middleware that redirects requests to a canonical host.
class CanonicalHost
def initialize(app, host=nil, &block)
@app = app
@host = (block_given? && block.call) || host
end
def call(env)
if url = url(env)
[301, { 'Location' => url }, ['Redirecting...']]
else
" Vim filetype detection file
" Language: Ruby
" Maintainer: Tyler Hunt <tyler@tylerhunt.com>
" Version: 1
" Last Change: 2010 May 26
"
augroup ruby
" Ruby metafiles
au! BufRead,BufNewFile Gemfile setfiletype ruby
au! BufRead,BufNewFile config.ru setfiletype ruby
@tylerhunt
tylerhunt / coerce_blanks.rb
Created January 5, 2011 13:54
A Rails plugin for stripping strings on models and replacing empty strings with nil values.
module CoerceBlanks
def write_attribute(attr_name, value)
if value.is_a?(String)
value.strip!
value = nil if value.empty?
end
super
end
end
def render_once options = nil, extra_options = {}, &block
@rendered_once ||= []
args = [options, extra_options]
return '' if @rendered_once.include?(args.hash)
@rendered_once << args.hash
render options, extra_options, &block
end
@tylerhunt
tylerhunt / jRumble Bookmarklet
Created April 4, 2011 19:01
Let's get ready to rumble!
javascript:var%20d=document,x=d.createElement('scr'+'ipt'),z=d.createElement('scr'+'ipt'),b=d.body;x.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js');z.setAttribute('src','http://jackrugile.com/jrumble/js/jrumble.1.0.js');b.appendChild(x);b.appendChild(z);setTimeout(function(){jQuery('body%20*').jrumble({rumbleEvent:'constant'});},500);
@tylerhunt
tylerhunt / Gemfile
Created June 21, 2011 12:38
Removing Rails version from Gemfile causes Rails to be downgraded upon `bundle update rails`
source 'http://rubygems.org/'
gem 'rails' # was '3.0.7'
gem 'coercion', '0.0.2'
gem 'gowalla', '0.5.7'
gem 'haml', '3.1.1'
gem 'sass', '3.1.1'
group :development, :test do
@tylerhunt
tylerhunt / hswitch.rb
Created July 11, 2011 15:25
Switches Keys for Multiple Heroku Accounts
#!/usr/bin/ruby
require 'fileutils'
account = ARGV.first
unless account
puts "Usage: #{File.basename(__FILE__)} <account>"
exit(1)
end
@tylerhunt
tylerhunt / cunt_catcher.rb
Created October 31, 2011 23:17 — forked from r38y/cunt.rb
Help prevent typos
module CuntCatcher
def cunt
warn "I'm guessing you meant 'count'?"
count
end
end
class Object
include CuntCatcher
end
require 'bundler/setup'
require 'sinatra/base'
require 'rack/contrib'
# The project root directory
$root = ::File.dirname(__FILE__)
class SinatraStaticServer < Sinatra::Base
get(/.+/) do
@tylerhunt
tylerhunt / deploy.sh
Created November 3, 2012 00:47
Heroku Deploy Script
#!/bin/bash
args=`getopt r:m $*`
if [ $? != 0 ]; then
echo "Usage: $0 [-r heroku] [-m]"
exit 2
fi
set -- $args