Skip to content

Instantly share code, notes, and snippets.

View mdwhatcott's full-sized avatar

Michael Whatcott mdwhatcott

View GitHub Profile

Window Management (BetterSnapTool):

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

top left             ⌘+⌥+⌃+u
top right ⌘+⌥+⌃+o
@mdwhatcott
mdwhatcott / s3_presign.py
Last active April 19, 2021 14:02
Generate a pre-signed S3 URL (valid for 20 years) with nothing but the standard library.
#!/usr/bin/env python
"""
Generates a pre-signed S3 URL using a valid key pair that lasts for 20 years.
Reference: http://forrst.com/posts/Python_method_for_creating_authenticated_s3_URLs-uUM
"""
import base64, hmac, os, sha, sys, time, urllib
@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:

@mdwhatcott
mdwhatcott / Iterative_example_test.go
Created February 28, 2014 05:20
Example of using table-driven testing with GoConvey (also shows how to use `Reset`)
package regexps
import (
"fmt"
"regexp"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
@mdwhatcott
mdwhatcott / auto-run.py
Created February 20, 2014 05:41
Auto-run `go test` in the console
#!/usr/bin/env python
"""
This script scans the current working directory for changes to .go files and
runs `go test` in each folder where *_test.go files are found. It does this
indefinitely or until a KeyboardInterrupt is raised (<Ctrl+c>). This script
passes the verbosity command line argument (-v) to `go test`.
"""
@mdwhatcott
mdwhatcott / goconvey-v2-example.go
Last active January 4, 2016 07:59
Detailed example of the 2.0 update to GoConvey
// NOTE: This is examples code which never actually became valid because we found a better way.
func TestScoring(t *testing.T) {
Convey("Subject: Bowling Game Scoring", t, func(c Context, so Assertion) {
var game *Game // Whatever you do, don't do this: game := NewGame()
// Otherwise nested closures won't reference the correct instance
Convey("Given a fresh score card", c, func() {
game = NewGame()
@mdwhatcott
mdwhatcott / mnemonic.py
Last active January 2, 2016 01:29
Here's some Python code to convert a passage of text into first-letter sequences to facilitate memorization:
def first_letter_mnemonic(text):
words = text.split()
letters = []
for word in words:
letters.append(word[0])
if word[-1] in ',-': # inline punctuation
letters.append(word[-1])
elif word[-1] in '.;:?!': # delimiting punctuation
@mdwhatcott
mdwhatcott / logger.py
Created June 13, 2013 15:28
Write log messages to the console (sys.stdout) and to a log file, all managed as a context manager.
import sys
class Logger(object):
"""
Write log messages to the console (sys.stdout) and to a log file,
all managed as a context manager:
>>> with Logger('log_file.txt'):
... print "Hello, World!" # goes to stdout and to the log file
@mdwhatcott
mdwhatcott / binary.py
Last active February 23, 2019 23:08
Chunks the bit groupings in bytes if the specified length is divisible by 8.
def main():
print ' 42 in 32 bits:', bits(42, 32)
print '-42 in 32 bits:', bits(-42, 32)
print '-42 in 20 bits:', bits(-42, 20)
print
def bits(number, size_in_bits):
"""
The bin() function is *REALLY* unhelpful when working with negative numbers.
@mdwhatcott
mdwhatcott / html_compile.py
Created September 17, 2012 22:39 — forked from anglepoised/html_compile.py
Python script to compile .shtml files with server side includes down to flat HTML suitable for hosting on S3 or where SSIs aren't supported.
#! /usr/bin/env python
import os
import re
import shutil
from os.path import splitext
SOURCE = os.getcwd() + "/www/"
TARGET = os.getcwd() + "/compiled/"
if not os.path.exists(TARGET):