This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
def signum(n): | |
return int(n / abs(n)) if n else 0 | |
def i2s(n, b=10, d=string.digits+string.ascii_lowercase): | |
assert 2 <= b <= len(d) | |
return d[0] if n == 0 else ('-' + i2s(abs(n), b, d)) if n < 0 else (i2s(n//b, b, d) + d[n % b]).lstrip(d[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[ -n "$2" ] || { echo "$0 <repo-url> <repo-path-file>">&2; exit 1; } | |
repo="$1" | |
dirn=$(dirname "$2") | |
[ "$dirn" = . ] && dirn='' | |
fnam=$(basename "$2") | |
exec git archive --remote="${repo}" HEAD:"${dirn}" -- "${fnam}" | tar xO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
"syscall" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package spaces | |
import "regexp" | |
import "strings" | |
var spaces_re = regexp.MustCompile(`\s+`) // *any* space | |
const sp = " " // *the* space | |
// Replace *any* sequence of white-space chars with single vanilla space ('\x20') | |
func Strip(s string) string { return strings.TrimSpace(spaces_re.ReplaceAllString(s, sp)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"path" | |
"io/ioutil" | |
"strings" | |
) | |
import "net/http" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Idea from https://stackoverflow.com/questions/11354518/ | |
COMMIT := $(shell git log | grep -wm1 commit | cut -d' ' -f2) | |
GITTAG := $(shell git tag -n | tail -n1 | cut -d ' ' -f1) | |
BDATE := $(shell date -u '+%FT%T%z') | |
GOFILES := $(wildcard *.go) | |
GO_LD_FLAGS := -ldflags "-X main.commit=$(COMMIT) -X main.version=$(GITTAG) -X main.built=$(BDATE)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"bytes" | |
"net/http" | |
"mime/multipart" | |
"io" | |
"os" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
) | |
func assert(e error, message string, args ...interface{}) { | |
if e != nil { | |
args = append(args, e) | |
log.Fatal(message + ": %v", args...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import logging "log" | |
import "fmt" | |
import "strings" | |
type LogLevel int | |
const ( | |
FATAL = LogLevel(0) + iota |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// https://github.com/coreos/go-systemd/blob/master/daemon/sdnotify.go | |
import ( | |
"net" | |
"os" | |
"fmt" | |
) | |
const ( |