Skip to content

Instantly share code, notes, and snippets.

View rhcarvalho's full-sized avatar
🎥
Building something new

Rodolfo Carvalho rhcarvalho

🎥
Building something new
View GitHub Profile
@rhcarvalho
rhcarvalho / tgz.go
Created July 25, 2016 13:47
Experiment writing to a tar.gz in Go
//+build ignore
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"io"
"os"
@rhcarvalho
rhcarvalho / init.coffee
Last active June 17, 2016 16:08
Automatic integration with Godep using Atom's Init Script
# Add the lines below to your init.coffee file to automatically update the
# GOPATH used by tools like those from the go-plus plugin.
fs = require("fs")
path = require("path")
for p in atom.project.getPaths()
workspace = path.join(p, "Godeps", "_workspace")
if fs.existsSync(workspace)
process.env.GOPATH = workspace + ":" + process.env.GOPATH
@rhcarvalho
rhcarvalho / console
Created April 5, 2016 12:29
Programs cannot catch SIGKILL
$ go build sigkill.go
$ ./sigkill &
[1] 13969
$ kill %1
[1]+ Exit 2 ./sigkill
@rhcarvalho
rhcarvalho / console
Last active April 1, 2016 19:53
Insistent cleanup of terminating Go program
$ go run panic.go
2016/04/01 21:51:12 start
2016/04/01 21:51:12 creating container "680b98d36ce2e667"...
^C2016/04/01 21:51:15 removing container "680b98d36ce2e667"...
2016/04/01 21:51:16 removed "680b98d36ce2e667"
2016/04/01 21:51:16 done
2016/04/01 21:51:16 run time panic: early termination
$ go run panic.go
2016/04/01 21:51:18 start
2016/04/01 21:51:18 creating container "7265daca397afe17"...
@rhcarvalho
rhcarvalho / console
Created March 31, 2016 08:57
Go executes deferred calls on panic
$ go run signal.go
1/3 = 0
1/2 = 0
1/1 = 1
hello from deferred call!
panic: runtime error: integer divide by zero
[signal 0x8 code=0x1 addr=0x400d3d pc=0x400d3d]
goroutine 1 [running]:
main.main()
@rhcarvalho
rhcarvalho / console
Created March 29, 2016 19:57
data race example
$ go run -race racy.go
==================
WARNING: DATA RACE
Write by goroutine 5:
main.func·001()
/tmp/racy.go:12 +0x158
Previous read by main goroutine:
main.main()
/tmp/racy.go:15 +0xdb
@rhcarvalho
rhcarvalho / commands
Created March 29, 2016 19:49
data race in openshift/origin PR 8268
git fetch upstream pull/8268/merge:pr8268
git checkout pr8268
godep go build -race ./cmd/oc
./oc rsync docs/ frontend-1-208zy:/ --watch > stdout.log 2> stderr.log
+ set -o errexit
+ rm -rf /tmp/gopath
+ mkdir -p /tmp/gopath/src/github.com/openshift /tmp/gopath/src/k8s.io
+ export GOPATH=/tmp/gopath
+ GOPATH=/tmp/gopath
+ cd /tmp/gopath/src/github.com/openshift
+ git clone https://github.com/openshift/origin
Cloning into 'origin'...
+ cd /tmp/gopath/src/k8s.io
+ git clone https://github.com/kubernetes/kubernetes
@rhcarvalho
rhcarvalho / console.log
Last active February 23, 2016 09:46
go1.6-crash-experiments
✔ /tmp
10:31 $ go version
go version go1.6 linux/amd64
✔ /tmp
10:31 $ go run deadlock.go
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/tmp/deadlock.go:12 +0x76
@rhcarvalho
rhcarvalho / bench_go1.4.2.txt
Last active October 6, 2015 11:22
How to check if a string is empty in Go
$ go test -v -bench . strcmp_test.go
testing: warning: no tests to run
PASS
BenchmarkEmptyString 2000000000 0.78 ns/op
BenchmarkLen0 2000000000 0.94 ns/op
ok command-line-arguments 3.617s