Skip to content

Instantly share code, notes, and snippets.

View kbaird's full-sized avatar
💭
Homo sapiens... for now.

Kevin C. Baird kbaird

💭
Homo sapiens... for now.
View GitHub Profile
@kbaird
kbaird / remove_trailing_whitespace.sh
Created October 17, 2013 19:13
Remove trailing whitespace from file args
#!/bin/bash
perl -pi -e 's#\s*\n#\n#g' $@
@kbaird
kbaird / migrate_back_to_master.sh
Created September 20, 2013 16:19
Shell script for reverting migrations found in a dev branch and not found in master branch.
#!/bin/bash
git diff --name-only master db/migrate/ | sed "s/migrate\//migrate\n/" | grep -v migrate | sed "s/\_/\n/" | grep -v rb | xargs -I vnum rake db:migrate:down VERSION=vnum
@kbaird
kbaird / inheritance.js
Created August 8, 2012 19:17
Simple JavaScript subclassing
/*
* Simple JS subclassing, shamelessly stolen from
* http://kevinoncode.blogspot.com/2011/04/understanding-javascript-inheritance.html
*/
function Super() {
this.value = 42;
}
function Sub(parent) {
@kbaird
kbaird / git_binary_diff_gist
Created May 10, 2012 16:01
Binary diff setup in .git/config
[diff "bz2"]
binary = true
textconv = /bin/bzcat
[diff "gzip"]
binary = true
textconv = /bin/zcat
[diff "tar"]
binary = true
textconv = tar --to-stdout -xf
[diff "tar-bz2"]
@kbaird
kbaird / greek_lambda.rb
Created December 20, 2011 20:09
Nerdy syntactic sugar to allow the Greek letter lambda for Procs in Ruby.
# encoding: UTF-8
module Kernel
alias_method :λ, :lambda
end
=begin
Allows code like this, using the actual Greek λ character:
#!/usr/bin/env ruby
# vehicle.rb
class Vehicle
MEDIUM = :ground
def self.medium; self::MEDIUM; end
# Using MEDIUM instead of self::MEDIUM makes Aircraft use the ground
end
class Car < Vehicle; end
#!/usr/bin/env ruby
# liberal_sort_by.rb
class Array
def liberal_sort
liberal_sort_by { |x| x }
end
def liberal_sort_by(&block)
pertains, others = partition(&block)
pertains.sort_by(&block) + others
#!/usr/bin/env ruby
# libertarianism_made_easy.rb
module LibertarianismMadeEasy
attr_accessor :is_government
def acceptable_to?(some_action)
not is_government
end
:abbr teh the
augroup filetypedetect
au! BufRead,BufNewFile *.asd setfiletype lisp
au! BufRead,BufNewFile *.cgi setfiletype ruby
au! BufRead,BufNewFile *.dbk setfiletype xml
au! BufRead,BufNewFile *.rb_txt setfiletype ruby
au! BufRead,BufNewFile *.rbx setfiletype ruby
au! BufRead,BufNewFile *.ly setfiletype tex
augroup END