Skip to content

Instantly share code, notes, and snippets.

View mdwhatcott's full-sized avatar

Michael Whatcott mdwhatcott

View GitHub Profile
@mdwhatcott
mdwhatcott / keybase.md
Last active August 29, 2015 13:57
Keybase declaration

Keybase proof

I hereby claim:

  • I am mdwhatcott on github.
  • I am mdwhatcott (https://keybase.io/mdwhatcott) on keybase.
  • I have a public key whose fingerprint is 7F78 8BE6 A44F 4654 DE8D 083B B6B5 11D7 6F72 29F8

To claim this, I am signing this object:

Window Management (BetterSnapTool):

left half            ⌘+⌥+⌃+j
right half           ⌘+⌥+⌃+l
top half             ⌘+⌥+⌃+i
bottom half          ⌘+⌥+⌃+,
center               ⌘+⌥+⌃+k

top left             ⌘+⌥+⌃+u
top right ⌘+⌥+⌃+o
@mdwhatcott
mdwhatcott / gtd_next_actions.py
Created October 30, 2014 04:57
Gather all actions across all projects in a directory and group them according to their context. Helps with GTD.
"""
# Dependencies:
- https://github.com/russross/blackfriday-tool
- http://wkhtmltopdf.org/
TODO: this whole thing should be put under test.
TODO: it would be great to know how long a project (or task) is taking
"""
@mdwhatcott
mdwhatcott / exhaust_waitgroup_hack.go
Created February 24, 2015 05:45
Don't ever do this (but it works).
package main
import (
"fmt"
"strings"
"sync"
)
func main() {
var waiter sync.WaitGroup
package utils
// toInt is a port of the little endian path of the .Net BitConverter.ToInt32
// function. It does exactly what toIntReversed (below) does but it operates
// on a slice that is already in the expected order. If your slice is in
// reverse order, use toIntReversed (below) instead.
// For 4-byte integers the gist of this algorithm is:
// return int(b[0]) | int(b[1])<<8 | int(b[2])<<16 | int(b[3])<<24
// The for loop implementation allows byte slices of arbitrary length
// (up to 4 bytes because we return an int) to be converted to integer
@mdwhatcott
mdwhatcott / traverse.go
Created July 29, 2015 21:06
Recursively find a value in a JSON object that can contain fields and values, as long as all values are only JSON objects with similarly defined objects with fields and values.
// traverse recursively finds a value in a JSON object that can contain fields and values,
// as long as all values are only JSON objects with similarly defined objects with fields and values.
// This works with structures like the US and International Street APIs.
// example: traverse(d, "components", "primary_number) // will return the primary number of the candidate)
func traverse(i interface{}, keys ...string) interface{} {
var (
found bool
object map[string]interface{}
)
object, found = i.(map[string]interface{})
@mdwhatcott
mdwhatcott / testing.go
Created August 13, 2015 17:29
golang testing package improvements
package something
import "testing"
type MyFixture struct {
*testing.T
sut Something // stuff under test
}
@mdwhatcott
mdwhatcott / echo_server.go
Created September 21, 2015 21:44
HTTP server that dumps the over-the-wire HTTP request it serves.
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func main() {
@mdwhatcott
mdwhatcott / memory_file.py
Created February 29, 2012 19:51
Context-managed, iterable, in-memory file
from StringIO import StringIO
class MemoryFile(StringIO):
"""
This abstraction provides context management and line-iteration over the
built-in StringIO class, making it more fully behave like a file object.
Unfortunately, iteration is not (yet?) memory-efficient for large files.
"""
def __init__(self, text=''):
@mdwhatcott
mdwhatcott / read_parallel.py
Created May 25, 2012 21:05
Read any number of files in parallel.
FIRST = 'path to first file'
SECOND = 'path to second file'
def main():
with open(FIRST) as first, open(SECOND) as second:
for line1, line2 in read_parallel(first, second):
pass # process lines