Skip to content

Instantly share code, notes, and snippets.


David Brady dbrady

View GitHub Profile
dbrady / utah_fire_omg.rb
Created Jun 28, 2012
Ruby script to generate an animated map of Utah that is very, VERY on fire
View utah_fire_omg.rb
#!/usr/bin/env ruby
# Generate an astonishingly accurate, animated map of Utah with
# thousands of wildfire pins scattered around it by throwing dozens of
# random lat/lng pairs at the google static maps API.
# NOTE: This script requires ImageMagick. Good luck with that.
# returns a latitude and longitude that lies within the state of Utah
dbrady /
Created Apr 6, 2012
Rand using bc
# Linear Congruential Generator using bc
# Note the shenanigans necessary to seed the generator with the epoch
# time: $(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") does nothing
# more than return the current date in epoch seconds, which we use to
# seed the generator. This generator is due to Knuth, and cited in
# Numerical Recipes in C, chapter 7. It's fast on old 32-bit machines
# but not a very good RNG:
dbrady / dangeromatic.rb
Created Mar 16, 2012
Graph Splitter Complexity-o-Mat (Inspired by Jack Danger)
View dangeromatic.rb
# Inspired by Jack "Best Name Ever" Danger Carty's talk at MWRC 2012
def cplx(n)
def dangeromat(n)
puts "Interconnection Complexity: #{cplx(n)}"
b=n/2; a=n-b
puts "If you split your project evenly an app and a service api, you get"
dbrady / descendants.rb
Created Mar 15, 2012
Return the list of descendants of a class
View descendants.rb
class Class
def extend?(klass)
superclass && (superclass == klass || superclass.extend?(klass))
def descendants do |constant_name|
constant = eval(constant_name.to_s)
if constant && constant.is_a?(Class) && constant.extend?(self)
dbrady / day_labels.rb
Created Mar 12, 2012
pattern for maps that take n-dimensional inputs and yield m-dimensional inputs
View day_labels.rb
# Draw day labels, e.g. "Mon 1/30", "Tue 1/31", "Wed 2/1" etc.
day_labels = (0...DAYS_PER_WEEK).map {|d| (start_date + d).strftime("%a %-m/%-d")}
# HEY GISTERS LOOK HERE: Okay, I have a loop that iterates 0 to
# 6, and I need this for the day_label in question, but I *also*
# need to know the x-coordinate at which to draw the label. What
# I would like in this SPECIFIC case, is a loop construct that
# somehow yields the day_label and x-coordinate, perhaps as a
# pair, which I guess I could do with a map. But in general I'm
# looking for a loop construct that accepts n-dimensional inputs
dbrady / gist:2023535
Created Mar 12, 2012
Iterating by columns with a nudge factor
We couldn’t find that file to show.
dbrady / vector3.rb
Created Mar 7, 2012
Ruby 3D Vector w/UTF
View vector3.rb
#!/usr/bin/env ruby
# encoding: utf-8
class Vector
attr_accessor :x, :y, :z
def initialize(x,y,z)
@x,@y,@z = x,y,z
dbrady / bfr.rb
Created Mar 6, 2012
Brainfuck to Ruby compiler
View bfr.rb
#!/usr/bin/env ruby
# bfr - brainfuck 2 ruby
# Usage:
# ./bfr "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
# => Hello World!
INDENT = " "
dbrady / nested_contexts.rb
Created Oct 19, 2011
Is this good RSpec style?
View nested_contexts.rb
# 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 / lolrails.rb
Created Oct 17, 2011
ActiveRecord models deny their ancestry. What gives?
View lolrails.rb
class Bonk < ActiveRecord::Base
Bonk.ancestors.include? ActiveRecord::Base
# => true
Bonk.is_a? ActiveRecord::Base
# => false
# um...WAT
You can’t perform that action at this time.