Skip to content

Instantly share code, notes, and snippets.

View jasonkeene's full-sized avatar
:shipit:

Jason Keene jasonkeene

:shipit:
View GitHub Profile
@jasonkeene
jasonkeene / before_onpar_test.go
Last active December 24, 2021 03:14
Golang Test Setup
// Before method that runs before each test and can communicate values via arguments
// Pros: Consolidate setup code
// Pros: No sharing of memory between tests, can run in parallel
// Pros: Use symbols for dependencies
// Cons: A little bit magical with using reflection.
func TestSomething(t *testing.T) {
t.Before(func (t *testing.T) (*db.Conn, map[string]interface{}) {
return createDBConn(t), createFixture()
type ExportedType struct {
unguarded int
// iternal state that is subject to concurrent access and requires locking
protected struct {
sync.RWMutex
guarded1 int
guarded2 int
guarded3 int
}
@jasonkeene
jasonkeene / go-intro.md
Last active May 25, 2019 18:28
Notes for the Programming Languages Club session on Go

Go is an imperative, compiled, statically-typed, garbage-collected, concurrent, general purpose programming language. It emphasizes fast compilation, fast execution, and a conservative, simple language design.

What is Go good for?

Server Software

Go has modern, native implementations of many networking protocols.

@jasonkeene
jasonkeene / Dockerfile
Created March 6, 2019 00:10
Go Modules Dockerfile
FROM golang:1.12 as builder
WORKDIR /root
ENV GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0
COPY /go.mod /go.sum /root/
@jasonkeene
jasonkeene / README.md
Last active November 30, 2018 23:03
Kubernetes God Mode PodSecurityPolicy

God Mode

This PodSecurityPolicy allows pretty much anything to run in a given namespace.

The Role and RoleBinding are namespaced objects so when you apply it you should make sure it gets applied to the appropriate namespace.

Also, delete this when you are done.

@jasonkeene
jasonkeene / notes.md
Last active May 13, 2018 23:48
Notes for Protobuf Episode

Why use protobuf?

Protocol buffers are a flexible and efficient way to represent structured data.

  • Binary Serialzation
  • Schema vs Schemaless
  • Parse time
  • Backwards compatibility
  • Cross language/platform
@jasonkeene
jasonkeene / dump_descriptor.go
Created April 17, 2018 01:32
An Exercise in dumping the file descriptor of the grpc-go helloworld example
package main
import (
"bytes"
"compress/gzip"
"io/ioutil"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/golang/protobuf/proto"
@jasonkeene
jasonkeene / client.go
Last active April 21, 2018 17:04
I/O Blocking in http.Handler
package main
import (
"log"
"net"
)
func main() {
println("dialing")
conn, err := net.Dial("tcp", "localhost:12345")
@jasonkeene
jasonkeene / upload-to-om.sh
Last active January 16, 2018 11:35
Download a product from GCS and upload it to OpsMan
#!/bin/bash
set -e
tile=pivotal-container-service-0.7.1-build.6.pivotal
om_username=some-username
om_password=some-password
om_target=https://1.2.3.4
mkdir -p $HOME/tile-dl
cd $HOME/tile-dl
@jasonkeene
jasonkeene / ort_bench_test.go
Created November 25, 2017 16:59
Stable Sort Benchmarks
package main
import (
"math/rand"
"sort"
"testing"
)
func benchSort(size int, b *testing.B) {
b.StopTimer()