Skip to content

Instantly share code, notes, and snippets.

@localshred
localshred / .vimrc
Created September 25, 2012 17:23
Vimrc
"-------------------------------------------------------------------[Vundle]----
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'kien/ctrlp.vim'
Bundle 'mileszs/ack.vim'
@localshred
localshred / grades.txt
Created September 13, 2012 23:26
Weighted, sorted scores for finovate grades (seen at http://bankinnovation.net/2012/09/finovate-fall-2012-demo-performance-scores-and-reviews/). MoneyDesktop just shy of top score! And yes, I work for MD (full disclosure).
# Columns: Score, Coolness, Want, Profit, Name
11.25 A- A- A- Mortgage Harmony
11.00 A A B MoneyDesktop
10.75 A- B+ A- Backbase
10.50 B+ A B+ Credit Sesame
10.25 A- A- B- Playmoolah
10.25 A- B+ B+ PayTap
10.25 A A C+ Dashlane
10.00 B+ B- A Currency Cloud
10.00 B+ A B- Deluxe SwitchAgent
@localshred
localshred / pre-receive.rb
Created August 29, 2012 02:29
Reject commits if updating non-dev branch and the Gemfile was changed and contains a list of rejectable words (e.g. git, tag, branch, path, etc.)
#!/usr/bin/env ruby
BRANCHES = %w( qa stage stable)
REJECT_OPTIONS = %w( git tag branch path )
old_sha, new_sha, ref = STDIN.read.split(' ')
exit 0 unless BRANCHES.include?(ref.split('/').last)
diff = %x{ git diff-index --cached --name-only #{old_sha} 2> /dev/null }
#puts diff.inspect
@localshred
localshred / gist:3362147
Created August 15, 2012 18:24
View shake
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setDuration:0.08];
[animation setRepeatCount:3];
[animation setAutoreverses:YES];
[animation setFromValue:[NSValue valueWithCGPoint:
CGPointMake([formContainer center].x - 20.0f, [formContainer center].y)]];
animation setToValue:[NSValue valueWithCGPoint:
CGPointMake([formContainer center].x + 20.0f, [formContainer center].y)]];
[[formContainer layer] addAnimation:animation forKey:@"position"];
@localshred
localshred / symbolized_hash_keys.rb
Created August 9, 2012 17:56
Symbolize keys doesn't do what I expected when to_sym equivalent keys exist.
# Fascinating behavior of symbolize_keys usage. If you have two keys that
# are `to_sym` equivalents, the non-symbol version is the winner,
# regardless of the order in the hash.
# For some reason I expected if a symbol key existed it would be
# the winner.
1.9.2p290 :002 > {"one" => 1, :one => 2}.symbolize_keys
=> {:one=>1}
1.9.2p290 :001 > {:one => 1, "one" => 2}.symbolize_keys
=> {:one=>2}
@localshred
localshred / bdays.rb
Created May 18, 2012 17:27
Birthdays date calculator to show num days alive, leap years lived through, average age of a group of people (e.g. your fam). I dunno, fun to write at least.
require 'date'
today = Date.today
peeps = [
[:bj, 1983, 1, 18],
[:angelee, 1983, 12, 27],
[:bella, 2004, 11, 17],
[:anders, 2008, 6, 30],
[:india, 2012, 2, 23]
@localshred
localshred / 1.9.2_ex.irb
Created March 6, 2012 23:57
1.9.3 changes the behavior of "rescue else" in a method from previous ruby versions. A return in the method body will not trigger the else.
>> hmm
hello
I got here
in ensure
@localshred
localshred / binary_search.rb
Created February 28, 2012 07:22
Land of Lisp binary search algorithm in ruby. This is in stark contrast to my verbose approach in the summer of 2011: http://rand9.com/blog/picking-the-right-number-as-quickly-as-possible/
# set some vars
@high = 100
@low = 0
# Simply calc the midpoint (no remainder)
# of the high and low value (bit shift right)
def ask
(@high + @low) >> 1
end
@localshred
localshred / puts_watcher.rb
Created February 28, 2012 00:02
Have stdout/err output you just can't track down? Use this. It needs to be inserted in the earliest possible load path (like spec_helper or rails boot.rb)
def STDOUT.puts *args
super(*args)
STDERR.puts(caller[0..5]) if args.any?{|a| a.to_s =~ /my semi-unique string/ }
end
@localshred
localshred / git_helper_functions.sh
Created February 16, 2012 21:02
git helpers for mainline branch synchronization and checking
# Synchronize all mainline branches (master, qa, stage, stable)
function reposync() {
git fetch
git checkout master
git rebase origin/master
git checkout qa
git rebase origin/qa
git checkout stage
git rebase origin/stage
git checkout stable