Skip to content

Instantly share code, notes, and snippets.

Michael Whatcott mdwhatcott

Block or report user

Report or block mdwhatcott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mdwhatcott
mdwhatcott / tcr.sh
Last active Oct 5, 2019
test && commit || revert (a la Kent Beck)
View tcr.sh
#!/usr/bin/env bash
# TCR: test && commit || revert
# codified by Kent Beck
# https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864
function test() {
echo
cd `git rev-parse --show-toplevel`
go test ./...
@mdwhatcott
mdwhatcott / path.py
Created Mar 31, 2018
Dynamic attribute resolution to mimic a directory tree on a file system (either real or contrived).
View path.py
class Path(object):
"""
This nifty class uses dynamic attribute resolution to mimic a directory
tree on a file system (either real or contrived).
"""
def __init__(self, root, enforce_real_paths=False):
self.root___ = str(root)
self.navigation___ = []
self.enforce___ = enforce_real_paths
if self.enforce___ and not os.path.exists(self.root___):
@mdwhatcott
mdwhatcott / ordered_set.go
Created Mar 17, 2017
A simple, non-generic, somewhat wasteful, ordered set.
View ordered_set.go
package main
import "fmt"
import "strconv"
func main() {
a := NewOrderedSet()
for x := 0; x < 10; x++ {
a.Add(strconv.Itoa(x))
View Preferences.sublime-settings
{
"close_windows_when_empty": true,
"color_scheme": "Packages/Dayle Rees Color Schemes/sublime/darkside.tmTheme",
"draw_white_space": "all",
"font_face": "Source Code Pro",
"font_size": 19,
"ignored_packages":
[
"Vintage"
],
View Default (OSX).sublime-keymap
[
{ "keys": ["super+k", "super+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"}},
{ "keys": ["super+k", "super+m"], "command": "toggle_minimap" },
{ "keys": ["super+k", "super+t"], "command": "delete_trailing_spaces" }
]
View intelliJ-golang-tweaks.txt
Tweaks to Intellij:
Load Golang SDK
Mark Golang SDK as default
---
Keyboard Shortcuts:
Go to end of file
@mdwhatcott
mdwhatcott / validate_struct.go
Last active Nov 4, 2015
One way to validate struct fields that are strings, and that have a struct tag with a regex.
View validate_struct.go
package web
import (
"bytes"
"reflect"
"regexp"
"fmt"
"errors"
"strings"
)
@mdwhatcott
mdwhatcott / echo_server.go
Created Sep 21, 2015
HTTP server that dumps the over-the-wire HTTP request it serves.
View echo_server.go
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func main() {
@mdwhatcott
mdwhatcott / testing.go
Created Aug 13, 2015
golang testing package improvements
View testing.go
package something
import "testing"
type MyFixture struct {
*testing.T
sut Something // stuff under test
}
@mdwhatcott
mdwhatcott / traverse.go
Created Jul 29, 2015
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.
View traverse.go
// 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{})
You can’t perform that action at this time.