Skip to content

Instantly share code, notes, and snippets.

View thogg4's full-sized avatar

Tim Hogg thogg4

  • Test Double
  • North Carolina
  • X @thogg4
View GitHub Profile
@thogg4
thogg4 / gist:2993475
Created June 26, 2012 05:16
method on the Array class exactly like map, and collect
class Array
def just_like_map
r = []
self.each do |a|
r << yield(a)
end
r
end
end
@thogg4
thogg4 / gist:4029943
Created November 7, 2012 07:07
vimrc
call pathogen#runtime_append_all_bundles()
set noswapfile
filetype plugin indent on
" Make Vim remember cursor position
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g'\"" | endif
endif
@thogg4
thogg4 / gist:4029948
Created November 7, 2012 07:08
update_bundles
#!/usr/bin/env ruby
git_bundles = [
"git://github.com/msanders/snipmate.vim.git",
"git://github.com/thogg4/only-primary-nerdtree.git",
"git://github.com/timcharper/textile.vim.git",
"git://github.com/tpope/vim-cucumber.git",
"git://github.com/tpope/vim-fugitive.git",
"git://github.com/tpope/vim-git.git",
@thogg4
thogg4 / gist:4035402
Created November 7, 2012 23:41
postgres setup
create role myapp with createdb login password 'myapp'; // 'login' is optional if you plan to use psql
// with newer versions of Rails, 'rake db:create:all' will create all the databases listed in config/database.yml
select * from pg_user; // verify user created
select * from pg_shadow; // sysid listed here
create database myapp_development owner myapp;
create database myapp_test owner myapp;
@thogg4
thogg4 / except_catcher
Created January 4, 2013 04:30
rack middleware to catch exceptions
module Rack
class ExceptCatcher
def initialize(app, mailer)
@app = app
@mailer = mailer
@ignore = [404]
@hash_blacklist = %w(rack.session.options)
end
def call(env)
@thogg4
thogg4 / gist:4726987
Last active December 12, 2015 06:08
states/provinces
[['United States', [['Alabama', 'AL'], ['Alaska', 'AK'], ['Arizona', 'AZ'], ['Arkansas', 'AR'], ['California', 'CA'], ['Colorado', 'CO'], ['Connecticut', 'CT'], ['Delaware', 'DE'], ['District of Columbia', 'DC'], ['Florida', 'FL'], ['Georgia', 'GA'], ['Hawaii', 'HI'], ['Idaho', 'ID'], ['Illinois', 'IL'], ['Indiana', 'IN'], ['Iowa', 'IA'], ['Kansas', 'KS'], ['Kentucky', 'KY'], ['Louisiana', 'LA'], ['Maine', 'ME'], ['Maryland', 'MD'], ['Massachusetts', 'MA'], ['Michigan', 'MI'], ['Minnesota', 'MN'], ['Mississippi', 'MS'], ['Missouri', 'MO'], ['Montana', 'MT'], ['Nebraska', 'NE'], ['Nevada', 'NV'], ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], ['Ohio', 'OH'], ['Oklahoma', 'OK'], ['Oregon', 'OR'], ['Pennsylvania', 'PA'], ['Puerto Rico', 'PR'], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], ['Tennessee', 'TN'], ['Texas', 'TX'], ['Utah', 'UT'], ['Vermont', 'VT'], ['Virginia', 'VA'], ['Washington',
@thogg4
thogg4 / gist:5049028
Created February 27, 2013 16:04
Striper, for stripe
$ ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').prop('content'))
Striper.init
Striper =
init: (options) ->
defaults =
form: 'form.billing'
formButton: '.billing_button'
errorContainer: '.stripe_error'
# Public: Returns an Array of States (for use in Select Tags)
#
# short - (bool) If you want the function to return State Abreviations or full state names.
#
# Returns array.
def state_list(short=false)
if short
return ['AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY']
else
return ['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Wash
module ConditionalValidations
attr_accessor :validated_fields
def field_is_required?(field)
if !validated_fields.blank?
validated_fields.include?(field)
end
end
def conditionally_validate(attribute, options=nil)
@thogg4
thogg4 / gist:6001878
Created July 15, 2013 17:42
speed up cursor on mac
defaults write NSGlobalDomain KeyRepeat -int 0