Skip to content

Instantly share code, notes, and snippets.

View abraithwaite's full-sized avatar
:shipit:
:(){ :|:& };:

Alan Braithwaite abraithwaite

:shipit:
:(){ :|:& };:
View GitHub Profile
@abraithwaite
abraithwaite / test.go
Last active March 10, 2016 01:40
Golang "Canceling" (Useless without something like net.Context)
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan string, 1)
go func() { c <- mysleep() }()
function u2d () {
if [[ $# > 0 ]]; then
date -u -Iseconds -d @$1
else
date -u -Iseconds
fi
}
function d2u () {
if [[ $# > 0 ]]; then
@abraithwaite
abraithwaite / flags_pattern.go
Created June 16, 2016 21:18
Idea to use define common flags in go libraries.
package main
import (
"flag"
"fmt"
)
type Config struct {
A *string
B *int
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
vagrant at local in ~GOPATH/src/github.com/alecthomas/go_serialization_benchmarks (vendor●●)
21:21:28 $ go test -cpuprofile=cpu.out -bench='.*' ./
A test suite for benchmarking various Go serialization methods.
See README.md for details on running the benchmarks.
BenchmarkCapNProtoMarshal-4 3000000 522 ns/op 56 B/op 2 allocs/op
BenchmarkCapNProtoUnmarshal-4 3000000 477 ns/op 200 B/op 6 allocs/op
BenchmarkCapNProto2Marshal-4 2000000 851 ns/op 244 B/op 3 allocs/op
type ErrorSet []error
func (es ErrorSet) Error() string {
return errors.New("Error(s) encountered while processing. First error encountered was: %v")
}
func (s NodeName) FieldName(errs ErrorSet) FieldType {
...
if err != nil {
errs = append(errs, err)
@abraithwaite
abraithwaite / flagsexample.go
Created January 24, 2017 22:13
flags dragons
package main
import (
"fmt"
"flag"
)
var (
flagName = flag.String("name", "default", "myname")
flagPlace = flag.String("place", "france", "myname")
@abraithwaite
abraithwaite / config.go
Created March 15, 2017 03:03
Awesome way to do configuration in go. Taken from https://github.com/influxdata/telegraf
package main
import (
"io/ioutil"
"log"
"github.com/naoina/toml"
"github.com/naoina/toml/ast"
)
@abraithwaite
abraithwaite / 40305.patch
Created June 13, 2017 18:13
ZSH Patch without ChangeLog
From 34656ec2f00d6669cef56afdbffdd90639d7b465 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <[email protected]>
Date: Tue, 10 Jan 2017 19:18:52 +0000
Subject: [PATCH] 40305: fix some problems redisplaying command line after
interrupt.
Back off previous fix as this only covered some subset of problems.
Remaining problems happend after reset-prompt in TRAPINT.
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"