Skip to content

Instantly share code, notes, and snippets.

@kylelemons
kylelemons / output
Created June 28, 2011 04:24
Demonstrate timeouts
$ for WORKTIME in {1..5}0; do echo -n "$WORKTIME: "; ./timeout --timeout 25 --worktime $WORKTIME; done
10: Worker finished
20: Worker finished
30: Timeout
40: Timeout
50: Timeout
@kylelemons
kylelemons / getset.go
Created July 12, 2011 21:34
A (really naive) example of controlling variables via a goroutine
package main
import (
"fmt"
)
type Gender int
const (
Male Gender = iota
@kylelemons
kylelemons / compiler_output.txt
Created July 13, 2011 22:10
Possible compiler bug for a literal slice type in an if statement
$ 6g slice.go && sl -o slice slice.6
slice.go:11: syntax error: unexpected }, expecting := or = or comma
$ 6g -V
6g version weekly.2011-07-07 9100+
@kylelemons
kylelemons / 000unmarshnameslice.go
Created July 14, 2011 16:19
A potential bug in unmarshal with named slices
package main
import (
"fmt"
"xml"
"bytes"
)
type Slice struct {
ID string "ident" // or `xml:"ident"` with a newish weekly
@kylelemons
kylelemons / sdrw.go
Created July 18, 2011 22:08
Potential way to prefix a path to a response by injecting an extra layer into the ResponseWriter
type SubDirResponseWriter struct {
ResponseWriter
path string
}
func (w *SubDirResponseWriter) WriteHeader(code int) {
if code/100 == 3 {
loc := w.Header().Get("Location")
if len(loc) > 0 {
url := http.ParseURLReference(loc)
@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 / httpget.go
Created July 23, 2011 01:40
Send a bunch of HTTP requests via threads and goroutines
package main
import (
"fmt"
"http"
"flag"
"runtime"
"bytes"
"log"
)
@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 / ls.go
Created August 4, 2011 20:52
A simple file list program
package main
import (
"path/filepath"
"fmt"
"log"
"os"
)
type visitor struct {
@kylelemons
kylelemons / client.go
Created August 9, 2011 20:49 — forked from zhujo01/client.go
TLS echo server and client
package main
import (
"crypto/tls"
"io"
"log"
)
func main() {
conn, err := tls.Dial("tcp", "127.0.0.1:8000", nil)