Skip to content

Instantly share code, notes, and snippets.

View knzconnor's full-sized avatar

Kenzi Connor knzconnor

View GitHub Profile
namespace :db do
task :migrate => :clear_load_paths do
Dependencies.load_paths = @old_load_paths
end
task :clear_load_paths do
@old_load_paths = Dependencies.load_paths
Dependencies.load_paths = []
end
end
@knzconnor
knzconnor / method_defined_where.rb
Created December 16, 2008 19:16
Determining where in the inheritance chain a method is defined (ruby).
def Object.method_defined_where(method)
self.ancestors.detect { |a| a.methods(false).include?(method.to_s) }
end
#Usage - define in your .irbrc and then:
#File.method_defined_where('read')
#=> IO
#Alternatively it has been added to my copy of utility_belt: http://github.com/timocratic/utility-belt/commit/74397c4f8be135cf46f65ca509ddb90e2e47799e

Note to Self

Test

Tests build confidence. Write 'em. They'll save your ass, and they'll let you take a chainsaw to your code without being afraid of unintended consequences.

Automate

def foo(value)
"#{value}foo"
end
[1,2].map &method(:foo)
#=> ["1foo", "2foo"]
def foo(value)
"#{value[0]}foo"
end
[[1,2],[3,4]].map &method(:foo)
test = Rake::Task['test']
test.clear
desc 'Run all units, functionals, integration, libs'
task :test do
run_sets_of_tests(%w(test:units test:functionals test:integration test:libs))
end
@knzconnor
knzconnor / autoexec.cfg
Created January 23, 2009 20:27
Quake 3 config file - put in base3q folder
set w1 "weapon 5; bind mouse3 vstr w2; echo ROCKET LAUNCHER"
set w2 "weapon 7; bind mouse3 vstr w1; echo RAIL GUN"
bind mouse3 vstr w1
seta com_maxfps "125"
seta r_finish "0"
seta cg_fov "120"
seta sensitivity "5"
set "zoom1" " cg_fov 60 ; sensitivity 2 ; bind mouse2 vstr zoom0 "
set "zoom0" " cg_fov 120 ; sensitivity 5 ; bind mouse2 vstr zoom1 "
@knzconnor
knzconnor / irb_from_script.rb
Created February 21, 2009 00:46
call irb from script context
#stolen from http://pastie.org/395671 twitter:@seacreature. Just repo'ed here so I can find it again
require "irb"
IRB.setup(nil)
IRB.conf[:MAIN_CONTEXT] = IRB::Context.new(IRB::Irb.new)
require "irb/ext/multi-irb"
IRB.irb(nil,binding)
class RspecInTU
class << self
alias it define_method
end
it "should say hello" do
puts "hello"
end
end
RspecInTU.new.send "should say hello"
#Or just check-out: http://github.com/timocratic/test_benchmark/tree/master
#It's only one file too: http://github.com/timocratic/test_benchmark/blob/832b2217451b49ed218d2db31dfad2b81a2399eb/lib/test_benchmark.rb
#Go ahead and steal anything you want from it - or even better fork it and add what features you like
@knzconnor
knzconnor / git-filter-directory.sh
Created March 30, 2009 02:02
some git directory filtering
git filter-branch -f --subdirectory-filter 'directory' #promote
git filter-branch -f --index-filter 'git rm -r --cached --ignore-unmatch directory' HEAD #delete
#http://git.or.cz/gitwiki/GraftPoint
echo "$commit-id $graft-id" >> .git/info/grafts
git filter-branch $graft-id..HEAD