Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am paddycarver on github.
  • I am paddycarver (https://keybase.io/paddycarver) on keybase.
  • I have a public key ASD5wBuaVIpLpcjb7XF-30QZy-QAMdIMSjzFMpIq65X_1Qo

To claim this, I am signing this object:

function prompt_char {
git branch >/dev/null 2>/dev/null && echo '%' && return
echo '$'
}
function get_directory {
DIR=${PWD/#$HOME/\~}
if [[ ! -f ~/.specialdirs || ! -r ~/.specialdirs ]]; then
echo $DIR && return
fi
@paddycarver
paddycarver / test.sh
Last active January 25, 2021 00:00
Testing a Go package with subpackages and getting good coverage reports.
#! /bin/bash
go get -u github.com/golang/lint/golint
go get -u github.com/paddyforan/combinedcoverage
go get -u github.com/wadey/gocovmerge
cd $GOPATH/src/path/to/your/package
go vet $(go list ./... | grep -v '/vendor/')
go list ./... | grep -v /vendor/ | xargs -L1 golint
mkdir -p coverage
@paddycarver
paddycarver / cafe.go
Created January 29, 2016 08:28
Whippersnapper.com concurrency exercises
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func useComputer(tourists chan int, done chan struct{}) {
@paddycarver
paddycarver / makefile
Created August 10, 2015 23:29
Run `go vet` on all the Go packages in a directory, then run all their tests, writing test coverage reports to `coverage/pkg.path.out`
SUBPACKAGES := $(foreach pkg,$(sort $(dir $(shell find . -type f -name '*.go'))),$(patsubst %/,%,${pkg}))
# run tests with coverage reports.
test:
@${GO} vet ./...
@mkdir -p coverage
@for pkg in ${SUBPACKAGES}; do \
go test $$pkg -v -coverprofile=coverage/$${pkg/\//.}.out; \
done
$ cat /proc/meminfo
MemTotal: 3800808 kB
MemFree: 163492 kB
MemAvailable: 2301612 kB
Buffers: 147920 kB
Cached: 2088052 kB
SwapCached: 0 kB
Active: 2386304 kB
Inactive: 999916 kB
Active(anon): 1150640 kB
path := strings.TrimRight(os.Getenv("GOPATH"), "/") + "/src/github.com/DramaFever/go-logging/log.go"
line := 463
if testing.Coverage() > 0 {
path = "github.com/DramaFever/go-logging/_test/_obj_test/log.go"
line = 448
}
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func main() {
http.Handle("/", getRouter())
@paddycarver
paddycarver / itertest.go
Last active August 29, 2015 14:04
itertest.go contains a test for how many iterations of PBKDF2 and SHA-256 you need to make hashing take at least 1 second. pass.go contains helper functions for working with passwords.
package main
import (
"crypto/rand"
"crypto/sha256"
"fmt"
"time"
"code.google.com/p/go.crypto/pbkdf2"
)
@paddycarver
paddycarver / nsq-Dockerfile
Created July 11, 2014 10:20
Dockerfiles for NSQ images.
FROM google/golang
RUN go get github.com/tools/godep
RUN go get github.com/bmizerany/assert
ADD . /gopath/src/github.com/bitly/nsq
RUN godep get github.com/bitly/nsq/...
RUN cd /gopath/src/github.com/bitly/nsq && godep restore