Skip to content

Instantly share code, notes, and snippets.

View j16r's full-sized avatar
😑

John Barker j16r

😑
  • Colorado
View GitHub Profile
@j16r
j16r / gist:ac274feb99780bac85f5
Created June 25, 2015 15:05
Golang and ParseECPrivateKey
# According to the go src (https://github.com/golang/go/blob/master/src/crypto/x509/sec1_test.go)
# this is how to use openssl to generate an EC private key. Go can't read it
# however.
# openssl ecparam -name secp521r1 -genkey -param_enc explicit -outform PEM -out $@
# e.g:
got asn1: structure error: tags don't match (6 vs {class:0 tag:16 length:450 isCompound:true}) {optional:false ex
plicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 set:false omitEmpty:false} ObjectIdentifier @4
# For debugging the private key
package sets
import "testing"
func BenchmarkUnitSet(b *testing.B) {
for i := 0; i < b.N; i++ {
values := make(map[int]struct{})
for j := 0; j < 1000; j++ {
values[j] = struct{}{}
}
@j16r
j16r / pointers.go
Created November 9, 2015 15:27
I was curious if go allows for dangling pointers when you resize a collection
package main
import "fmt"
func main() {
collection := []int{1, 2, 3, 4, 5}
ptr1 := &collection[0]
ptr2 := &collection[1]
ptr3 := &collection[2]
@j16r
j16r / traits.go
Created November 9, 2015 15:29
An array of traits?
package main
import "fmt"
type Trait interface {
String() string
}
type Traitable struct {
}
@j16r
j16r / logf.go
Created November 9, 2015 15:31
`go vet` treats Logf as a special function, even for custom definitions. `go` used to do this, but looks like it was fixed in 1.5.
package main
import "fmt"
type Level int
const CODE Level = 1
type Logger struct {
}
@j16r
j16r / mem.go
Created November 9, 2015 15:32
Go allows for reading the VM's memory statistics, neat!
package main
import (
"fmt"
"runtime"
)
func main() {
s := new(runtime.MemStats)
runtime.ReadMemStats(s)
@j16r
j16r / archive-org.sh
Created January 27, 2017 23:26
This is a bash script designed for backing up every repo in a github organization and encrypted the repo archives.
#!/usr/bin/env bash -e
organization=$1
if [ -z $organization ]; then
echo "Usage: $0 <organization>"
echo
echo "Make sure to specify \$GITHUB_API_TOKEN as an environment variable."
echo "Acquire one here: https://github.com/settings/tokens"
echo
@j16r
j16r / archive-org.sh
Last active June 14, 2017 13:12
This is a bash script designed for backing up every repo in a github organization and encrypted the repo archives.
#!/usr/bin/env bash -e
organization=$1
if [ -z $organization ]; then
echo "Usage: $0 <organization>"
echo
echo "Make sure to specify \$GITHUB_API_TOKEN as an environment variable."
echo "Acquire one here: https://github.com/settings/tokens"
echo
04b1284c8c594867a13a16fa513016a006f7a7b1c92727ca3060c33955644fbeb3b7db1bd5d67b6249cdf1fb43305eefd081c363b0664ebb95b8b40e37e2290b51
@j16r
j16r / assert_on_methods.go
Created November 19, 2018 22:35 — forked from dimroc/assert_on_methods.go
Finding it hard to shoe horn into table driven tests
func TestHeightsController_Index(t *testing.T) {
threshold := big.NewInt(2)
tests := []struct {
name string
status int
}{
{"good clients", 200},
// Hard to do error cases without adding an if with difference setup. could add test helpers...
}