Skip to content

Instantly share code, notes, and snippets.

View mathie's full-sized avatar

Graeme Mathieson mathie

View GitHub Profile
@mathie
mathie / fixtures_test.rb
Created April 11, 2011 13:26
If you've got to use fixtures, the least you can do is make sure they're actually valid.
require 'test_helper'
class FixturesTest < ActiveSupport::TestCase
fixtures(:all).each do |fixture|
define_method("test: #{fixture} is valid") do
fixture_instances = @loaded_fixtures[fixture]
invalid_fixtures = fixture_instances.keys.select do |fixture_name|
!fixture_instances[fixture_name].find.valid?
end
@mathie
mathie / vim-startup-time.log
Created January 10, 2012 12:55
This is the startup trace from opening a particularly long test file in vim (7933 LOC). How would I determine and eliminate the slowdown?
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.006 000.006: --- VIM STARTING ---
000.096 000.090: Allocated generic buffers
000.291 000.195: locale set
000.300 000.009: GUI prepared
000.302 000.002: clipboard setup
000.309 000.007: window checked
@mathie
mathie / character-frequency.rb
Created February 4, 2012 12:19
Given a string, tell me how many of each character I'll need. Surprisingly useful when trying to typeset a sentence and check to see if you've enough type!
#!/usr/bin/env ruby
puts "Gies a phrase"
str = STDIN.readline.chomp
characters = Hash.new(0)
str.each_char do |char|
characters[char] += 1
end
@mathie
mathie / gist:3817785
Created October 2, 2012 09:29
Convert a bunch of png files that are already set for Retina display to the right filename, and produce non-Retina variants.
for i in *.png; do
j=${i/.png/@2x.png}
mv $i $j
convert $j -resize 50% $i
done
@mathie
mathie / rackspace-bootstrap.sh
Created December 14, 2012 12:21
Template for bootstrapping a pristine Ubuntu 12.04 node on Rackspace Cloud far enough that I can then bootstrap with puppet 3.0.x and a sensible Ruby install.
#!/bin/sh -e
export DEBIAN_FRONTEND=noninteractive
HOSTNAME=${1}
DOMAINNAME=${2}
PUPPET_MANIFEST=${3}
PUPPETMASTER_IP=${4}
FQDN=${HOSTNAME}.${DOMAINNAME}
@mathie
mathie / emily-words-christmas-2012.md
Last active December 10, 2015 09:28
Mogie curated a list of words that Emily could say -- in context -- during Christmas 2012. I figured an electronic version was quite useful. :) 87 words counted so far and that's definitely incomplete -- after putting it into categories, the food category is definitely lacking, at least.

Songs

  • Ba ba back sheep (Ba ba, black sheep, in tune)
  • Appa barshy too woo (Happy birthday to you, in tune).
  • Tinko, tinko lil sar, ow I won'a are (Twinkle, twinkle, little star, how I wonder what you are, in tune).
  • Da-na-na-na-na-na-na-na Bat-Man! (in tune, mostly)

Food related

  • A'done (all done)
@mathie
mathie / gist:5055484
Created February 28, 2013 09:29
Install ruby-1.9.3-p385 with performance patches on Mac OS X (homebrew, rbenv).
brew install autoconf readline apple-gcc42
curl https://raw.github.com/gist/4772546/2-1.9.3-p385-patched.sh > ~/.rbenv/plugins/ruby-build/share/ruby-build/1.9.3-p385-perf
env CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` CC=/usr/local/bin/gcc-4.2 rbenv install 1.9.3-p385-perf
@mathie
mathie / phantomjs.pp
Created April 14, 2013 15:15
Puppet class for installing phantomjs. An example of using curl to grab a tarball for installation.
class phantomjs {
include xvfb
$version = '1.8.1'
$basename = "phantomjs-${version}-linux-x86_64"
$tarball = "${basename}.tar.bz2"
$tarball_path = "/opt/${tarball}"
$url = "http://phantomjs.googlecode.com/files/${tarball}"
$destdir = "/opt/${basename}"
--==============================
-- OmniFocus > Prepare Task Completion Report
-- Version 2.0.0
-- Written By: Ben Waldie <[email protected]>
-- http://www.automatedworkflows.com
-- Description: This script retrieves a list of OmniFocus tasks completed today, yesterday, this week, last week, or this month. It then summarizes the tasks in a new Evernote note.
-- Version History:
-- 1.0.0 - Initial release
-- 2.0.0 - Added support for including full project paths, context names, estimate time, start dates, modification dates, completion dates, and notes in task reports.
-- This property controls whether full project paths (including parent folders) are displayed
property includeFullProjectPaths : true
-- These properties control whether additional task content is displayed
property includeTaskContext : true
property includeTaskEstimatedTime : true
property includeTaskStartDate : true
property includeTaskModificationDate : false
property includeTaskCompletionDate : true
property includeTaskNotes : true