Skip to content

Instantly share code, notes, and snippets.

@kylelemons
kylelemons / container.sh
Last active August 29, 2015 14:17
Generic container management script
#!/bin/bash
# Always run from the script local directory:
cd "$(dirname "${BASH_SOURCE[0]}")"
# Constants:
IMAGE="yourprefix/imagename"
CONTAINER="containername"
# Configuration variables:
@kylelemons
kylelemons / .tmux.conf
Last active August 29, 2015 14:12
TMux Config
#
# General settings
#
# Set terminal titles
set -g set-titles on
# Expect UTF-8
set -g utf8 on
@kylelemons
kylelemons / stackerror.go
Created June 20, 2014 23:03
This is a playground paste that demonstrates extracting the caller and call for error messages
package main
import (
"fmt"
"log"
"path/filepath"
"runtime"
"strings"
"unicode"
)
@kylelemons
kylelemons / timestubs.go
Created December 18, 2013 19:25
Example of how to stub out time.Now
package foo
import "time"
// in your main package
var timeNow = time.Now
// in the _test.go:
func init() {
// Panic if any tests cause timeNow to be called without stubbing it out
@kylelemons
kylelemons / datemath.go
Created September 2, 2013 17:44
Fun with Date arithmetic!
package main
import (
"fmt"
"log"
"math/rand"
"time"
)
type Snapshot struct {
$ time ./client_cpp
real 1m48.071s
user 0m1.955s
sys 1m45.919s
# ./trace.d
dtrace: script './trace.d' matched 22 probes
CPU ID FUNCTION:NAME
2 1 :BEGIN Tracing...
@kylelemons
kylelemons / shuntingyard.go
Created April 10, 2013 04:39
Quick hacked-up shunting yard algorithm
package main
import (
"io"
"log"
"strings"
)
type (
Operator string
@kylelemons
kylelemons / insensitiveMux.go
Last active December 14, 2015 15:48
Straw man case-insensitive serve mux
package main
import "net/http"
import pathpkg "path"
import "strings"
type InsensitiveMux struct {
handlers map[string]http.Handler
isDir map[string]bool
}
@kylelemons
kylelemons / jsonrpc.go
Created March 3, 2013 03:24
Type safe decoding of JSON RPC (ish) with json.RawMessage. Yes, I know this isn't precisely JSON RPC, but it's illustrative.
package main
import (
"bytes"
"encoding/json"
"log"
"os"
"strings"
)
@kylelemons
kylelemons / enc.go
Created February 18, 2013 20:03
Simple RSA encryption/decryption. It uses the same public and private key, so it encrypts a message to itself. It can only encrypt short data (RSA is more for encrypting the key to the data than the data itself).
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/pem"
"flag"
"io/ioutil"