Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tomhennigan on github.
  • I am tomhennigan (https://keybase.io/tomhennigan) on keybase.
  • I have a public key ASBYlo52VYIkmCXuhjwFIkiDCp8HcTEgwkXCgEF4nMMLugo

To claim this, I am signing this object:

@tomhennigan
tomhennigan / derp.py
Created September 4, 2015 07:41
matrix representation of a graph
def mkmatrix(size):
matrix = []
for _ in xrange(size):
matrix.append([False] * size)
return matrix
def addedge(matrix, nodea, nodeb):
matrix[nodea][nodeb] = True
matrix[nodeb][nodea] = True
@tomhennigan
tomhennigan / gist:28026171c89d2fd3ec69
Last active August 29, 2015 14:04
Mesos logo Unicode art
echo " ╱┃┃╲ "
echo "$(tput setaf 6) ╱┃┃╲$(tput sgr0)╲┃┃╱$(tput setaf 6)╱┃┃╲$(tput sgr0) $(hostname)"
echo "$(tput setaf 6)┃╲╲┃┃╱╱┃┃╲╲┃┃╱╱┃$(tput sgr0) "
echo "$(tput setaf 6)┃╱╱┃$(tput sgr0)┃╲$(tput setaf 6)╲┃┃╱$(tput sgr0)╱┃$(tput setaf 6)┃╲╲┃$(tput sgr0) Mesos: http://1.2.3.4:1234/"
echo "$(tput setaf 6)┃╲╲┃$(tput sgr0)┃╱╱┃┃╲╲┃$(tput setaf 6)┃╱╱┃$(tput sgr0) Marathon: http://1.2.3.4:1234/"
echo "$(tput setaf 6)┃╱╱┃$(tput sgr0)┃╲╲┃┃╱╱┃$(tput setaf 6)┃╲╲┃$(tput sgr0) Chronos: http://1.2.3.4:1234/"
echo "$(tput setaf 6) ╲┃$(tput sgr0)┃╱╱┃┃╲╲┃$(tput setaf 6)┃╱$(tput sgr0) "
echo " ╲┃┃╱ "
@tomhennigan
tomhennigan / delegate_example.py
Created March 26, 2013 14:20
Delegate method pattern for Python classes.
from delegates import DelegateProviderMixin, notify_delegates
class Something(DelegateProviderMixin):
@notify_delegates
def do_something(self):
print 'do_something'
def do_something_else(self):
print 'do_something_else'
@tomhennigan
tomhennigan / test_relativedelta.py
Created January 7, 2013 16:18
relativedelta comparator test (<, >, <=, >=, __cmp__)
from dateutil.relativedelta import relativedelta
import unittest
class Test_relativedelta(unittest.TestCase):
def test___lt__(self):
# For all fields test that a relative delta with only a single field
# set behaves as expected.
self.assertLess(relativedelta(years=1990), relativedelta(years=2012))
self.assertLess(relativedelta(months=1), relativedelta(months=12))
@tomhennigan
tomhennigan / delegate_example.py
Last active December 10, 2015 09:39
Delegate method pattern in python
def notify_delegates(method):
"""Decorator to call delegate methods. When decorating a method it will
call `onBeforeMethodName` and `onAfterMethodName` (uppercasing the first
letter of the method name).
Delegate methods are called before and after the actual method is called.
On the after method the return value from the method is passed in as the
`ret_value` keyword arg."""
# Figure out delegate method names.
@tomhennigan
tomhennigan / benchfish.md
Last active December 10, 2015 05:28
Benchmarking Blowfish

MacBook Pro 13" i7 @ 2.7GHz, 16GB

4 rounds mean (from 100 iters): 0.00127s per call (~784.45 hashes/s)
5 rounds mean (from 100 iters): 0.00236s per call (~423.79 hashes/s)
6 rounds mean (from 100 iters): 0.00454s per call (~220.03 hashes/s)
7 rounds mean (from 100 iters): 0.01016s per call (~98.45 hashes/s)
8 rounds mean (from 100 iters): 0.01793s per call (~55.78 hashes/s)
9 rounds mean (from 100 iters): 0.03526s per call (~28.36 hashes/s)
10 rounds mean (from 71 iters): 0.07035s per call (~14.22 hashes/s)
@tomhennigan
tomhennigan / fliptables.sh
Created November 9, 2012 16:25
Happy friday
#!/bin/sh
frames=( "(╮°-°)╮ ┳━┳" "(╯°o°)╮ ┳━┳" "(╯°o°)╯ ︵ ╡" "(╯°o°)╯ ︵┻━┻" "(╮°□°)╮ ┻━┻" );
for frame in "${frames[@]}"; do
printf "%s\033[0K\r" "${frame}";
sleep 0.5;
done
@tomhennigan
tomhennigan / matcher.php
Created August 17, 2012 17:10
matcher '(.*@.*)' '$1' < input_file_with_emails
#!/usr/bin/env php
<?php
define('DEBUG', false);
class Logger
{
private $fp;
public function __construct($fp) {
$this->fp = $fp;
tell application "Google Chrome"
set win to make new window with properties {mode:"incognito"}
activate
tell application "System Events" to keystroke "f" using {command down, shift down}
tell win
set URL of active tab to "http://cl.ly/0t1J3d0c1o3i"
end tell
end tell