Skip to content

Instantly share code, notes, and snippets.

@kylelemons
kylelemons / reman.go
Created June 7, 2011 00:44
A sketch of a resource manager in Go
package main
import (
"fmt"
"time"
"sync"
)
// A Token represents resources allocated. It must be given
// back to the Manager to free the resource.
@kylelemons
kylelemons / scripttemplate.sh
Created July 19, 2011 22:52
BASH Script template
###
### Usage: blah [<options>]
###
### Description of the script
###
### Options:
### -f --flag
### Description of the flag
### -o --option <arg>
### Description of the option and argument
@kylelemons
kylelemons / Makefile
Created August 3, 2011 17:21
A demonstration listener in Go
include $(GOROOT)/src/Make.inc
TARG=l
DEP=
GOFILES=\
main.go\
pkgdir=$(GOROOT)/pkg/$(GOOS)_$(GOARCH)
PREREQ+=$(foreach PKG,$(DEP),$(pkgdir)/$(PKG).a)
@kylelemons
kylelemons / enum.go
Created September 8, 2011 18:49
Enum types (bitshifted too)
package main
import (
"fmt"
"strings"
)
type foo int
const (
One foo = iota
@kylelemons
kylelemons / Makefile
Created October 20, 2011 18:27
A Makefile for protocol buffers in Go
include $(GOROOT)/src/Make.inc
PROTOFILES=$(wildcard *.proto)
GOPROTOFILES=$(patsubst %.proto,%.pb.go,$(PROTOFILES))
TARG=protopackage
GOFILES=\
$(GOPROTOFILES)\
CLEANFILES+=$(GOPROTOFILES)
@djsutherland
djsutherland / example.hmm
Created November 1, 2011 05:10
Code for a Hidden Markov Model, along with some sample data / parameters for testing.
4 # number of states
START
COLD
HOT
END
3 # size of vocab
1
2
3
@kylelemons
kylelemons / gencert.sh
Created November 17, 2011 02:55
Generate a key/certificate
#!/bin/bash
# Usage: gencert.sh
# Generates SSL certificates
set -e
PREFIX="my_"
function oops() {
echo "Failed."
exit 1
@kylelemons
kylelemons / graph.go
Created November 17, 2011 19:01
A fun little graph demo
package main
import (
"fmt"
"sync"
)
type WaitList []*sync.WaitGroup
func (l WaitList) Done() {
for _, wg := range l {
@kylelemons
kylelemons / infinite.go
Created January 12, 2012 01:27
Infinite channel buffer without "sync"
// assume the following exist and are set to unbuffered channels:
// var (
// next chan Type
// in chan Type
// )
go func() {
defer close(next)
// pending events (this is the "infinite" part)
@moraes
moraes / gist:2370781
Created April 12, 2012 20:32
GetPage for App Engine datastore (Go)
package foo
import (
"reflect"
"appengine"
"appengine/datastore"
)
var (