Skip to content

Instantly share code, notes, and snippets.

View ardavis's full-sized avatar

Andrew Davis ardavis

  • NASA - Kennedy Space Center
  • Kennedy Space Center, FL
View GitHub Profile
@coreyhaines
coreyhaines / A Description of Rules
Created August 15, 2012 03:45
100 x 100 Game of Life Kata
Write a system that evolves a 100 x 100 grid of cells
to the next generation according to the following rules.
1) Any living cell with less than 2 live neighbors dies
2) Any living cell with 2 or 3 live neighbors stays alive
3) Any living cell with more than 3 live neighbors dies
4) Any dead cell with exactly 3 lives neighbors comes to life
Note: A cell has 8 neighbors
...
ruby-1.9.2-p180 :001 > bunny = bunny = { bunny => bunny }
=> {nil=>nil}
ruby-1.9.2-p180 :002 > bunny = bunny = { bunny => bunny }
=> {{nil=>nil}=>{nil=>nil}}
ruby-1.9.2-p180 :003 > bunny = bunny = { bunny => bunny }
=> {{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}
ruby-1.9.2-p180 :004 > bunny = bunny = { bunny => bunny }
=> {{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}=>{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}}
ruby-1.9.2-p180 :005 > bunny = bunny = { bunny => bunny }
=> {{{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}=>{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}}=>{{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}=>{{{nil=>nil}=>{nil=>nil}}=>{{nil=>nil}=>{nil=>nil}}}}}
@BinaryMuse
BinaryMuse / setup_load_paths.rb
Created March 15, 2011 04:29
config/setup_load_paths.rb for Passenger and RVM using .rvmrc
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
raise "RVM ruby lib is currently unavailable."
end
@lucapette
lucapette / toys.rb
Created February 2, 2011 10:08
methods to create toys arrays and hashes
class Array
def self.toy(n=10, &block)
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end
end
class Hash
def self.toy(n=10)
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
end
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@mrrooijen
mrrooijen / Capistrano-Deployment-Recipe.rb
Created July 29, 2009 09:34
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment: