Skip to content

Instantly share code, notes, and snippets.

require 'formula'
class Dblatex < Formula
url 'http://downloads.sourceforge.net/project/dblatex/dblatex/dblatex-0.3/dblatex-0.3.tar.bz2'
homepage 'http://dblatex.sourceforge.net'
md5 '7de6bf72b8b2934169ce0ec911e966ed'
def install
system "python", "setup.py", "install", "--prefix=#{prefix}", "--install-scripts=#{bin}"
end
@gavinheavyside
gavinheavyside / Invoking
Created May 6, 2012 11:55
strip colons from filenames in an extracted report tarball
# from the top level of an extracted report tarball
$ find . -type d -depth 1 | xargs -I {} ./filename_fixer.sh {}
@gavinheavyside
gavinheavyside / array_aggregator.rb
Created July 19, 2012 19:20
a solution to the alphasights job quiz
# 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 / gist:3761159
Created September 21, 2012 12:14
Problem report from Tweetbot beta crash on 10.7.5
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 / hash_differences.rb
Last active January 4, 2016 16:39
Hash[] difference between Ruby 1.9 and 2.x
# 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 September 25, 2013 17:43
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.
#!/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 / Create PostGIS template
Last active October 30, 2018 10:36
Create a POSTGIS template database
-- From http://geospatial.nomad-labs.com/2006/12/24/postgis-template-database/
-- $ sudo su postgres
-- $ psql template1
\c template1
CREATE DATABASE template_postgis WITH template = template1;
-- set the 'datistemplate' record in the 'pg_database' table for
-- 'template_postgis' to TRUE indicating its a template
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
@gavinheavyside
gavinheavyside / fizzbuzz.rb
Last active September 27, 2019 08:43 — forked from mrb/fizzbuzz.rb
Writing FizzBuzz without modulus division or 'if'
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 / trivial_file_upload_service.rb
Created November 3, 2009 20:09
Trivial file upload service using Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
@gavinheavyside
gavinheavyside / mapreduce_conway.rb
Created September 19, 2010 20:02
A MapReduce algorithm for Conway's Game of Life
#!/usr/bin/env ruby
require 'rubygems'
require 'wukong'
# Given a file with the coordinate pair of a live cell on each line,
# generate the next iteration of Game of Life, using MapReduce
#
# The map phase takes each live cell, and outputs 9 key value pairs, 1 for
# each of the adjacent cells and itself. The reduce phase dedupes, detects