Skip to content

Instantly share code, notes, and snippets.

View ColinDKelley's full-sized avatar

Colin Kelley ColinDKelley

  • Invoca, Inc.
  • Santa Barbara, CA
View GitHub Profile
@ColinDKelley
ColinDKelley / gist:3702480
Created September 11, 2012 22:06
rr_monitoring
module RRMonitoring
class Statistic
STATS_HOST = "stats.ringrevenue.net"
STATS_PORT = 8125
def timing(name, &blk)
start = Time.now
yield
finish = Time.now
@ColinDKelley
ColinDKelley / elevation.rb
Created September 24, 2012 15:59
elevation
class Elevation
attr_reader :elevations
def initialize(elevations)
@elevations = elevations
highest = 0
@highest_lefts = @elevations.map { |elevation|
highest = Math.max(highest, elevation)
}
@ColinDKelley
ColinDKelley / min_max.rb
Created September 24, 2012 16:28
Math.min and Math.max
module Math
def self.min *args
args.min
end
def self.max *args
args.max
end
end
require 'rubygems'
#require 'rubygems/user_interaction' # Required with some older RubyGems
require 'isolate/now'
require 'eventmachine'
require 'em-websocket'
require 'em-http'
require 'nokogiri'
require 'json'
require 'pp'
@ColinDKelley
ColinDKelley / gist:5298850
Last active December 15, 2015 17:49
Script to compare failing Rails 3 tests cases across builds
build_numbers = [4036, 4037, 4041, 4044, 4045, 4048]
build_stats = build_numbers.map { |i| YAML.load_file("../shared/builds/#{i}/test_stats.yml") }
failing = build_stats.map do |run|
run.reduce([]) do |a, t|
t.last.each { |test_case, attrs| a << [t.first, test_case] if attrs.is_a?(Hash) && attrs['last_result'] != 'success' }
a
end
end
all_failing = failing.inject(&:|).sort
sometimes_failing = all_failing - failing.inject(&:&)
@ColinDKelley
ColinDKelley / prisoner_hat.md
Last active December 25, 2015 20:37
prisoner hat riddle

Answer

The tallest prisoner counts the white hats in front of him. If odd, he calls out "white"; if even he calls out "black".

Then each prisoner down the line makes the same calculation. If the color they compute is different from what was called out before them, they know their color is "white"; if it's the same, their color is "black". They call out their color.

Reasoning

Without magic comment: 3.93 seconds
With magic comment: 1.93 seconds
2X faster!

Solution to Three Gods Logic Puzzle

  1. Ask god A: "Would the other non-random god answer 'Ja' to the question 'Does the random god sit to your left1?'"

=> If the answer is 'Ja', then it's false (or random), therefore NonRandom1 = C; else it's true (or random), therefore NonRandom1 = B

  1. Ask gods[NonRandom1]: "Would the other non-random god answer 'Ja' to the question 'Does the random god sit to your left1?"
@ColinDKelley
ColinDKelley / hash_benchmark.rb
Last active November 5, 2016 17:16
hash benchmark
# -*- immutable: string -*-
require 'benchmark'
class Request
def initialize(first, last, city, state, country)
@hash =
{
'first' => first,
'last' => last,
Race 5 horses. Take the fastest 3 and race them against 2 chosen from the remainder. Repeat until there are are no remaining.
The final 3 from the last race are the fastest of the group.
races = 1 + (25 - 5)/2 = 11