Skip to content

Instantly share code, notes, and snippets.

View cmdrkeene's full-sized avatar

Brandon Keene cmdrkeene

View GitHub Profile
@cmdrkeene
cmdrkeene / debounce.js
Created May 25, 2017 21:43
Debounce - Throttle JS function call (minified)
function debounce(a,b,c){var d;return function(){var e=this,f=arguments;clearTimeout(d),d=setTimeout(function(){d=null,c||a.apply(e,f)},b),c&&!d&&a.apply(e,f)}}
@cmdrkeene
cmdrkeene / convert_images.sh
Created October 7, 2016 16:48
Convert Image Files on OSX
for i in *.png; do sips -s format jpeg $i --out Converted/$i.jpg;done
@cmdrkeene
cmdrkeene / log.go
Created May 1, 2015 19:12
An alternative leveled logger package that follows unix convention for output
// Package log follows linux output convention
// Top level functions like Test() and Verbose() set the package "mode"
package log
import (
"io/ioutil"
"log"
"os"
)
@cmdrkeene
cmdrkeene / log.go
Last active August 29, 2015 14:20
A simple leveled logger
package foo
import "os"
import "log"
// Level indicates Logger verbosity
type Level int
// LogLevel specifies the minimum level logged
var LogLevel = Debug
@cmdrkeene
cmdrkeene / api_doc.go
Created March 26, 2015 15:28
Generate API docs from source comments
package main
import (
"go/parser"
"go/token"
"io"
"strings"
)
// APIDoc is an API Documentation generator.
@cmdrkeene
cmdrkeene / gist:45863376fe7f23fdec35
Created January 22, 2015 16:59
Don't use primitives for things like email
// An electronic mail address
type email struct {
s string
}
var invalidEmail = errors.New("invalid email")
func newEmail(s string) (email, error) {
s = strings.Trim(s, " ")
@cmdrkeene
cmdrkeene / gist:ddc8e18a13016a056b33
Created January 22, 2015 01:36
Simple auto test for Go
#!/bin/bash
which entr > /dev/null
if [ $? -ne 0 ]; then
echo "installing entr"
brew install entr
else
echo "watching go files"
fi
@cmdrkeene
cmdrkeene / gist:6abefe35ad7f1fd3d2a2
Created October 29, 2014 17:49
uuid v4 and func to swap in test
var uuidFunc = uuidV4 // for swapping in test
func uuidV4() string {
b := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, b)
if err != nil {
panic(err)
}
b[6] = (b[6] & 0x0F) | 0x40
b[8] = (b[8] &^ 0x40) | 0x80
package main
import (
"errors"
"fmt"
"time"
)
var realError = errors.New("real")
var timeoutError = errors.New("timeout")
@cmdrkeene
cmdrkeene / gnuplot_chart.go
Created August 27, 2014 16:16
Scrap of a GNUPlot chart
// set term png
// set xlabel 'Samples'
// set ylabel 'MB'
// set output 'name.png'
// plot
// "name.dat" using 1:($2/1e6) title 'Sys' with lines,
// "name.dat" using 1:($3/1e6) title 'Alloc' with lines,
// "name.dat" using 1:($4/1e6) title 'Idle' with lines
type chart struct {
filename string