Skip to content

Instantly share code, notes, and snippets.

💭
Homo sapiens... for now.

Kevin C. Baird kbaird

💭
Homo sapiens... for now.
Block or report user

Report or block kbaird

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kbaird
kbaird / remove_trailing_whitespace.sh
Created Oct 17, 2013
Remove trailing whitespace from file args
View remove_trailing_whitespace.sh
#!/bin/bash
perl -pi -e 's#\s*\n#\n#g' $@
@kbaird
kbaird / migrate_back_to_master.sh
Created Sep 20, 2013
Shell script for reverting migrations found in a dev branch and not found in master branch.
View migrate_back_to_master.sh
#!/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 Aug 8, 2012
Simple JavaScript subclassing
View inheritance.js
/*
* 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
Binary diff setup in .git/config
View git_binary_diff_gist
[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 Dec 20, 2011
Nerdy syntactic sugar to allow the Greek letter lambda for Procs in Ruby.
View greek_lambda.rb
# encoding: UTF-8
module Kernel
alias_method :λ, :lambda
end
=begin
Allows code like this, using the actual Greek λ character:
View vehicles.rb
#!/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
View liberal_sort_by.rb
#!/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
View libertarianism_made_easy.rb
#!/usr/bin/env ruby
# libertarianism_made_easy.rb
module LibertarianismMadeEasy
attr_accessor :is_government
def acceptable_to?(some_action)
not is_government
end
View filetypes.vim
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
You can’t perform that action at this time.