Skip to content

Instantly share code, notes, and snippets.

View hwia_spec.rb
class HashWithIndifferentAccess < Hash
def [](key)
super(convert_key(key))
end
def []=(key, value)
super(convert_key(key), value)
end
def self.[] (*args)
@gavinheavyside
gavinheavyside / .gitconfig
Created Jun 20, 2014
Clean up your leftover merged git branches
View .gitconfig
[alias]
cleanup = "!git fetch -p && git branch --merged | grep -v '\\*\\|master\\|develop' | xargs -n 1 git branch -d"
View check_resque_working_jobs.go
// example program
package main
import (
"fmt"
"os"
"github.com/garyburd/redigo/redis"
)
View crap.rb
class Crap
attr_accessor :crappiness
def initialize(tolerability = 5)
@crappiness = 0
@tolerability = tolerability
end
def +(int)
result = dup
@gavinheavyside
gavinheavyside / hash_differences.rb
Last active Jan 4, 2016
Hash[] difference between Ruby 1.9 and 2.x
View hash_differences.rb
# Ruby 1.9:
Hash[ [ "", "key:value" ].map { |v| v.split( /:/) } ]
# => {"key"=>"value"}
# Ruby 2.0+:
Hash[ [ "", "key:value" ].map { |v| v.split( /:/) } ]
# ArgumentError: invalid number of elements (0 for 1..2)
# from (pry):1:in `[]'
@gavinheavyside
gavinheavyside / fix-credit-card-qif.rb
Created Sep 25, 2013
Reverse signs of transactions in a qif file, and open it (OS X) in the associated program. My bank generates .qif files for my credit card with credit & debit reversed compared with how my finance program wants them.
View fix-credit-card-qif.rb
#!/usr/bin/env ruby
require 'qif'
if ARGV.size != 1
$stderr.puts "usage: fix-credit-card-qif-and-load.rb <CC qif file>"
end
input_filename = ARGV[0]
output_filename = input_filename.sub(/\.qif/, "-fixed.qif")
@gavinheavyside
gavinheavyside / fizzbuzz.rb
Last active Sep 27, 2019 — forked from mrb/fizzbuzz.rb
Writing FizzBuzz without modulus division or 'if'
View fizzbuzz.rb
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
(1..100).zip(fizz, buzz) do |num, *fb|
puts fb.compact.reduce(:+) || num
end
@gavinheavyside
gavinheavyside / gist:3761159
Created Sep 21, 2012
Problem report from Tweetbot beta crash on 10.7.5
View gist:3761159
Process: Tweetbot [10718]
Path: /Applications/Tweetbot.app/Contents/MacOS/Tweetbot
Identifier: com.tapbots.TweetbotMacAdHoc
Version: 0.8.0 (758)
Code Type: X86-64 (Native)
Parent Process: launchd [261]
Date/Time: 2012-09-21 13:10:53.983 +0100
OS Version: Mac OS X 10.7.5 (11G56)
Report Version: 9
@gavinheavyside
gavinheavyside / array_aggregator.rb
Created Jul 19, 2012
a solution to the alphasights job quiz
View array_aggregator.rb
# As seen in Ruby Weekly newsletter http://rubyweekly.com/archive/102.html
# http://www.alphasights.com/apply/ruby-developer-london
by_time = log.reduce(Hash.new{|hash,key| hash[key] = {}}) do |memo, val|
memo[val[:time]].merge!(val.reject{|k,v| k == :time})
memo
end
by_time.map{|k,v| v.merge(time: k)}
@gavinheavyside
gavinheavyside / Invoking
Created May 6, 2012
strip colons from filenames in an extracted report tarball
View Invoking
# from the top level of an extracted report tarball
$ find . -type d -depth 1 | xargs -I {} ./filename_fixer.sh {}