Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile
@dbrady
dbrady / bfr.rb
Created March 6, 2012 02:28
Brainfuck to Ruby compiler
#!/usr/bin/env ruby
# bfr - brainfuck 2 ruby
# Usage:
# ./bfr "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
# => Hello World!
INDENT = " "
START_CODE = <<CODE
@dbrady
dbrady / nested_contexts.rb
Created October 19, 2011 23:59
Is this good RSpec style?
# RSpec style question for you here.
#
# Here is the code being tested:
#
# def extractor_name
# options[:extractor_name] || name
# end
#
# My question is, I feel like I'm doing a lot of setup and
@dbrady
dbrady / lolrails.rb
Created October 17, 2011 03:54
ActiveRecord models deny their ancestry. What gives?
class Bonk < ActiveRecord::Base
end
Bonk.ancestors.include? ActiveRecord::Base
# => true
Bonk.is_a? ActiveRecord::Base
# => false
# um...WAT
Fixjour do
define_builder(User) do |klass, overrides|
num = counter(:user)
klass.new(
:first_name => "Test#{num}",
:last_name => 'User',
:email => "user#{num}@totallyvaliddomain.com",
:password => 'password',
:password_confirmation => 'password',
:license => 'fakelicensenumber'
@dbrady
dbrady / logger_test.rb
Created August 15, 2011 16:40
logger methods expect a block, not a msg
log.debug false
# STDOUT => D, [2011-08-15T10:38:03.868973 #7762] DEBUG -- : nil
# => true
log.debug { false }
# STDOUT => D, [2011-08-15T10:38:08.492862 #7762] DEBUG -- : false
# => true
log.log Logger::DEBUG, false
# STDOUT => D, [2011-08-15T10:38:27.956344 #7762] DEBUG -- : false
@dbrady
dbrady / gist:1115797
Created July 30, 2011 18:01
__rvm_rvmrc_key is calling rspec. WAT
11:57:51 dbrady@shinything:~/.rvm ruby-1.9.2-p290
∫ type __rvm_rvmrc_key
__rvm_rvmrc_key is a function
__rvm_rvmrc_key ()
{
printf "$1" | time rspec '[#/.=]' _;
return $?
}
@dbrady
dbrady / gist:1115784
Created July 30, 2011 17:52
rvm cd with tracing enabled
11:49:52 dbrady@shinything:~/devel ruby-1.9.2-p290
∫ set -x; cd coffer; set +x
+ cd coffer
+ builtin cd coffer
+ local result=0
+ __rvm_project_rvmrc
+ local working_dir
+ [[ -n /Users/dbrady/.rvm/scripts ]]
+ source /Users/dbrady/.rvm/scripts/initialize
++ [[ -n 3.2.48(1)-release ]]
11:48:50 dbrady@shinything:~ ruby-1.9.2-p290
∫ type cd
cd is a function
cd ()
{
builtin cd "$@";
local result=$?;
__rvm_project_rvmrc;
__rvm_after_cd;
return $result
@dbrady
dbrady / gist:1114810
Created July 29, 2011 21:47
RVM choking on rspec, not remembering .rvmrc
# Does RVM now use some kind of file db system to remember .rvmrc files?
# The beginning of the (rather long) error message makes me wonder...
15:44:00 dbrady@shinything:~
∫ cd devel/coffer
rspec: No such file or directory
0.00 real 0.00 user 0.00 sys
@dbrady
dbrady / gist:1114747
Created July 29, 2011 21:11
RVM choking on rspec, not remembering .rvmrc
# After updating rvm, it is surprised and alarmed by .rvmrc files.
# It doesn't recognize them as trusted, and then crashes after
# approving them. Which means EVERY time I cd inside a project with
# an .rvmrc file, this happens:
#
# (Note that I am in ruby-1.9.2-p290@adsel. The 'coffer' directory
# has an .rvmrc file which specifies ruby-1.9.2-p180@coffer.)
15:05:52 dbrady@shinything:~/devel ruby-1.9.2-p290@adsel
∫ cd coffer