Skip to content

Instantly share code, notes, and snippets.

View mathie's full-sized avatar

Graeme Mathieson mathie

View GitHub Profile
@mathie
mathie / serial_number.rb
Created June 28, 2013 10:37
Using .new as a factory method. Good idea or crazy?
class SerialNumber
def self.new(str = nil)
# Our new method is really a factory to one of the concrete subclasses.
if SerialNumber == self
if str.blank?
nil
# Zigbee serial numbers are easy to spot; they start with eight '0's.
elsif str.strip =~ /^00000000/
ZigbeeSerialNumber.new(str)
else
@mathie
mathie / config.pp
Created July 1, 2013 14:48
Since Puppet stopped passing environment variables down to subprocesses (like, say, `apt-get install`), I've occasionally run into problems where a package postinst script relies on something in the environment. The PostgreSQL package (on Ubuntu 12.04 at least) is one such beast. It relies on the current locale (gleamed from the environment) to …
class postgresql::server::config {
exec {
'postgresql-drop-cluster':
command => '/usr/bin/pg_dropcluster --stop 9.1 main',
onlyif => "/usr/bin/psql -c '\\l+' |awk '/template0/ { print \$5 }' |grep 'SQL_ASCII'",
user => postgres,
notify => Exec['postgresql-create-cluster'];
'postgresql-create-cluster':
command => '/usr/bin/pg_createcluster --locale=en_GB.UTF-8 9.1 main',
@mathie
mathie / repo.pp
Created July 10, 2013 09:59
I've had this workaround in my puppet master module for ages. If any of the manifests change, then the puppet run will touch site.pp so the puppet master knows that the manifests need to be re-evaluated. This was to work around the puppet master not noticing that included manifests were changed. Question is: do I still need to do this with recen…
exec {
'touch-site-pp':
command => '/usr/bin/touch /etc/puppet/manifests/site.pp',
unless => '/usr/bin/test -z $(/usr/bin/find /etc/puppet/manifests/ -follow -newer /etc/puppet/manifests/site.pp)',
require => File['/etc/puppet/manifests'];
}
@mathie
mathie / save-pdf-to-evernote.applescript
Last active December 20, 2015 05:29
Automator Print Plugin to give you a menu item of "Save as PDF in Evernote". Just create a single "Run applescript" action with this code and save it.
on run {input, parameters}
tell application "Evernote"
repeat with pdf in input
create note from file pdf
end repeat
end tell
end run
@mathie
mathie / binding.clj
Created September 7, 2013 09:02
Demonstrating late binding in Clojure for @mr_urf
user=> (def foo 'hello)
#'user/foo
user=> (defn bar [] foo)
#'user/bar
user=> (bar)
hello
user=> (def foo 'world)
#'user/foo
user=> (bar)
world
@mathie
mathie / dladm-output.txt
Created September 16, 2013 09:40
dmesg output from BGE interfaces on SmartOS.
[root@10-60-4b-92-74-84 ~]# dladm show-phys
LINK MEDIA STATE SPEED DUPLEX DEVICE
e1000g0 Ethernet up 1000 full e1000g0
bge0 Ethernet up 1000 full bge0
bge1 Ethernet up 1000 full bge1
[root@10-60-4b-92-74-84 ~]# dladm show-link
LINK CLASS MTU STATE BRIDGE OVER
e1000g0 phys 1500 up -- --
bge0 phys 1500 up -- --
bge1 phys 1500 up -- --
@mathie
mathie / brew --config
Created September 20, 2013 15:54
PostgreSQL 9.3 failing to build
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/mxcl/homebrew
HEAD: dc7109eccb9753db6fefb40f3bd4b46c91647215
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit ivybridge
OS X: 10.9-x86_64
Xcode: 5.0
LLVM-GCC: N/A
Clang: 5.0 build 500
@mathie
mathie / todo-wishlist.md
Created February 13, 2014 11:16
My ideal task management system

My Ideal Task Management System

I’m not asking for much, really. I just want a task management system that provides me with the mechanisms I think I need in order to organise my life. Most of these are based on features I currently use in OmniFocus, and those I’ve wished were there at one time or another. In no particular order, they are:

  • An inbox which easily allows me to capture new tasks without thinking about organising them. I should be able to enter items into the inbox through a global shortcut on Mac OS X (ctrl-alt-space being my current one) and through a seamless interface on iOS (an obvious, always-available button in-app and importing Reminders from the native iOS app, so that I get Siri integration). And I should be able to capture emails into the inbox in such a way that it’s straightforward to get back to the original email (for replying).

  • It should be straightforward to work through the Inbox, moving individual tasks into the right place inside existing projects, or creating new pro

@mathie
mathie / keybase.md
Created December 20, 2014 12:30
Keybase proof

Keybase proof

I hereby claim:

  • I am mathie on github.
  • I am mathie (https://keybase.io/mathie) on keybase.
  • I have a public key whose fingerprint is CF61 9DD5 6116 D3CD 4380 C1AE 8F7E 58DD 002D C29B

To claim this, I am signing this object:

@mathie
mathie / proposal.md
Last active August 29, 2015 14:14
OSCON 2015 Proposal

OSCON 2015 Proposal

Title

You type "google.com" into your browser bar and press enter: what happens next?

Description

b We'll take a deep dive down the stack, into how the Internet works to magically make Google's home page appear in our web browser. Topics will range from URL parsing & DNS resolution, through HTTP, TCP, IP & routing, and all the way back up to browser rendering.