Skip to content

Instantly share code, notes, and snippets.

function supersay {
say -v princess '$1' &
say -v 'Agnes' $1 &
say -v 'Albert' $1 &
say -v 'Alex' $1 &
say -v 'Bad News' $1 &
say -v 'Bahh' $1 &
say -v 'Bells' $1 &
say -v 'Boing' $1 &
say -v 'Bruce' $1 &
@asross
asross / prisoner_problem_protocol.rb
Created January 25, 2014 23:30
A simulation of two solutions to the "prisoner and two switches" problem (http://www.braingle.com/brainteasers/18012/prisoners-and-2-switches-scenario-a.html)
class Leader
attr_reader :count
attr_reader :actually_visited
def initialize
@count = 1
@actually_visited = false
end
def respond_to_state(s)
@asross
asross / gist:6252889
Last active December 21, 2015 04:58
simple profiling
def time(&block)
$breakpoints = []
start = Time.now
yield
puts "----------------\n"
puts "Total time:"
puts "\t#{(Time.now - start).round(1)}s"
puts "Breakdown:"
$breakpoints.each.with_index do |(msg, t), i|
puts "\t#{(t-start).round(1)}s, breakpoint #{i} #{"(#{msg})" if msg}"
#!/usr/bin/env ruby
require 'time'
@default_root_dir = '~/code' # CHANGE THIS
def print_git_logs_since(date_str, root_directory)
logs_by_date_by_project = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] =[]}}
root_directory ||= @default_root_dir
@asross
asross / gist:4445325
Last active December 10, 2015 14:08
A bash function which, for arguments foo, bar, and baz, evaluates $ grep foo | grep bar | grep baz
function cgrep {
local command=""
for var in "$@"; do
command+="grep $var | "
done
eval ${command% | }
}