Skip to content

Instantly share code, notes, and snippets.

@ohthatjames
ohthatjames / run_this_in_shell.sh
Last active January 30, 2019 16:07
Stats of rails project over time
ruby -e 'require "date"; f=File.open("results.txt", "w"); (2013..2019).to_a.reverse.map{|y| (1..12).to_a.reverse.each{|m| d = Date.new(y, m, 1); next if d < Date.new(2013, 4, 3) || d > Date.new(2019, 2, 1); d = d.strftime("%Y-%m-%d"); commit = `git log --before=#{d} -n 1 --format=format:"%H"`.chomp; f.puts "#{d}: #{commit}"; f.puts `git checkout #{commit} && ruby stats.rb` }}'
@ohthatjames
ohthatjames / gist:de7a516ac13d0da2147e
Created November 28, 2014 13:20
Don't monkeypatch symbol for to_proc!
require 'blankslate'
class Functioniser < BlankSlate
class Func
def initialize(method)
@method = method
end
def to_proc
->(x, *args) { x.send(@method, *args)}
@ohthatjames
ohthatjames / gist:60a0b219443aeeb6cb41
Last active May 21, 2019 13:15
Registering to_procs without monkeypatching everything
require "set"
class Proc
def self.register_type(klass, proc)
@types_to_convert ||= {}
@types_to_convert[klass] = proc
end
def self.[](field)
-> (x) { (@types_to_convert || {})[field.class].call(field, x) }
@ohthatjames
ohthatjames / bitquest.rb
Created July 8, 2013 17:43
A DSL to get you through the first 6 levels of http://bitsquest.bitbucket.org/index.html
class Dsl
Change = Struct.new(:state, :new_directions)
def initialize
@state_count = 0
@sensor_changes = {}
end
def start(directions)
@start_directions = [directions].flatten