This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired by Jack "Best Name Ever" Danger Carty's talk at MWRC 2012 | |
def cplx(n) | |
(n**2-n)/2 | |
end | |
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" | |
puts "THE DANGER-O-MATIC EFFECT!!!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Class | |
def extend?(klass) | |
superclass && (superclass == klass || superclass.extend?(klass)) | |
end | |
def descendants | |
Module.constants.select do |constant_name| | |
constant = eval(constant_name.to_s) | |
if constant && constant.is_a?(Class) && constant.extend?(self) | |
constant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# bfr - brainfuck 2 ruby | |
# Usage: | |
# ./bfr "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | |
# => Hello World! | |
INDENT = " " | |
START_CODE = <<CODE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bonk < ActiveRecord::Base | |
end | |
Bonk.ancestors.include? ActiveRecord::Base | |
# => true | |
Bonk.is_a? ActiveRecord::Base | |
# => false | |
# um...WAT |