Skip to content

Instantly share code, notes, and snippets.

View jwhitmire's full-sized avatar

Jeff Whitmire jwhitmire

View GitHub Profile
@glv
glv / gist:1438719
Created December 6, 2011 16:05 — forked from gvaughn/gist:1436816
Conway's Game of Life in functional ruby
def evolve(generation)
live_neighbor_stats = generation_stats(generation)
live_neighbor_stats[3] + (live_neighbor_stats[2] & generation)
end
def generation_stats(live_cells)
live_cells.each_with_object(Hash.new(0)) {|live_cell, counter|
neighbors(*live_cell).each {|neighbor| counter[neighbor] += 1 }
}.each_with_object(Hash.new {|h,k| h[k] = []}) {|(cell, count), collector| collector[count] << cell}
end
@gvaughn
gvaughn / gist:1436816
Created December 6, 2011 04:57
Conway's Game of Life in functional ruby
def evolve(generation)
live_neighbor_stats = generation_stats(generation)
live_neighbor_stats[3] + (live_neighbor_stats[2] & generation)
end
def generation_stats(live_cells)
live_cells.each_with_object(Hash.new(0)) {|live_cell, counter|
neighbors(*live_cell).each {|neighbor| counter[neighbor] += 1 }
}.each_with_object(Hash.new {|h,k| h[k] = []}) {|(cell, count), collector| collector[count] << cell}
end
@ahoward
ahoward / net-http-debug.rb
Created December 10, 2010 20:06
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
@jwhitmire
jwhitmire / Ode to _why
Created August 20, 2010 02:50
Happy _whyday everybody! In honor of his absence, I've composed a little haiku that I think _why would appreciate. I think you'll agree it's quite ... like the man himself.
_why the lucky stiff
his brain was rare in the world
hackety hack -- brilliant
_why the lucky stiff
we miss him even today
how very poignant
_why the lucky stiff
sometimes didn't make much sense
# This is a snippet from my ~/.irbrc
# You need to gem install ruby2ruby ParseTree
# This is what you do with it
#
# > class Bar; define_method(:foo) { 'ou hai' }; end
# > puts Bar.to_ruby
# class Bar < Object
# def foo
# "ou hai"
@jamis
jamis / Easy Marshmallow Recipe
Created December 10, 2009 22:38
Easy Gourmet Marshmallows
EASY MARSHMALLOWS
-----------------
Marshmallows are perhaps one of the simplest confections you can make. They only
require a handful of ingredients, a batch can be thrown together in 10-15 minutes
(plus *cough* 3 hours for them to set), and you can flavor them however you like.
(You haven't LIVED until you've had coconut marshmallows!)
Hardware needed: