Skip to content

Instantly share code, notes, and snippets.

View j16r's full-sized avatar
😑

John Barker j16r

😑
  • Colorado
View GitHub Profile
@j16r
j16r / Wordler
Created February 24, 2022 12:42
#!/usr/bin/env ruby
require 'date'
day = (Date.today - Date.civil(2021, 6, 19)).to_i
won = rand(5)+1
puts "Wordle #{day} #{won}/6"
tiles = ['🟩','🟨','⬛️']
(1..won-1).each do |row|

This is a quick sketch of how I think terminology applies to the various kinds of mocking and test doubles that apply in Go.

In practice, the most effective way to mock things in Go is to use an interface, and then to substitute a specialized testing implementation in place of a real one. Wherever a substitute is used, I think this should be called a "double".

There is one specialization of a "double" and that is a "fake" implementation. Fakes can often have real world uses, e.g: "RamDiskDatabase", but are typically

@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...
}
04b1284c8c594867a13a16fa513016a006f7a7b1c92727ca3060c33955644fbeb3b7db1bd5d67b6249cdf1fb43305eefd081c363b0664ebb95b8b40e37e2290b51
@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
@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 / 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 / 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 / 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 / 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]