Skip to content

Instantly share code, notes, and snippets.

Colin Kelley ColinDKelley

Block or report user

Report or block ColinDKelley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:b936217351450310118533176f19fa62
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
View three_gods.md

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 / prisoner_hat.md
Last active Dec 25, 2015
prisoner hat riddle
View prisoner_hat.md

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

View meltdown.rb
tiles = {}
STDIN.readlines.map.with_index do |line, y|
x = 0
line.chomp.split(".").each do |segment|
unless segment.empty?
tile = [x, segment.size, segment[0]]
if value = tiles[tile]
tiles[tile] = [value.first, value.last + 1]
else
@ColinDKelley
ColinDKelley / example_usage.rb
Last active Aug 29, 2015
retry_on_exception
View example_usage.rb
result =
retry_on_exception(Timeout::Error, total_tries: 2) do
http_fe.post(...)
end
@ColinDKelley
ColinDKelley / parse_fig_leaf.rb
Created Aug 15, 2014
Fig leaf to intercept parse with American date formats like 03/04/05
View parse_fig_leaf.rb
module ParseFigLeaf
def parse(*args)
arg0 = args.first
arg0.is_a?(String) && arg0 =~ /\A\d\d[-\/]\d\d[-\/]\d\d/ and raise "Ambiguous parse format in #{arg0.inspect}"
super
end
end
class << Date
prepend ParseFigLeaf
View new_mysql2_improvements.rb
require 'mysql2'
module Invoca
module Mysql2AdapterKillOnTimeout
def kill(thread_id)
@connection.query("KILL #{thread_id}")
end
def execute(sql, name = nil)
View modified_singleton-example.rb
class Secrets
def initialize(secrets_path)
@hash = YAML.load_file(secrets_path)
end
def [](key)
@hash[key]
end
def set_instance
View parallel_sync-example.rb
responses =
ExceptionalSynchrony::ParallelSync.parallel(EventMachine) do |parallel|
messages.each do |message|
parallel.add { message.send }
end
end
responses.each { ... }
@ColinDKelley
ColinDKelley / lwq-example.rb
Created Mar 13, 2014
limited_work_queue-example.rb
View lwq-example.rb
queue = LimitedWorkQueue(EventMachine, 2)
messages.each do |message|
queue.add do
message.send # no more than 2 of these will run at the same time
end
end
You can’t perform that action at this time.