Skip to content

Instantly share code, notes, and snippets.

View smyrman's full-sized avatar

Sindre Røkenes Myren smyrman

View GitHub Profile
@smyrman
smyrman / Results
Last active June 7, 2022 09:08
Go copy vs append
$ go version
go version go1.18.3 darwin/amd64
$ go test -bench=. -benchmem
goos: darwin
goarch: amd64
pkg: play/bench
cpu: Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
BenchmarkAppendAllocInline/size=100-4 7442314 146.4 ns/op 896 B/op 1 allocs/op
BenchmarkAppendAllocInline/size=1000-4 929802 1397 ns/op 8192 B/op 1 allocs/op
@smyrman
smyrman / go13_const_err.go
Last active September 8, 2019 23:01
Go 1.13 const error example
pacakge x
const (
ErrPermissoinDenied = constErr("permissoin denied")
ErrInvalidParameters = constErr("invalid parameters")
)
type constErr string
func (err constErr) Is(target error) bool {

Contracts ... without contracts

This is an experimental rewrite of https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md to evaulate if type parameterized types as described in the contracts proposal could be implemented on top of the feature described in golang/go#33818. This to help evaluate weather the featuere could make sense for Go in the longer term, or if there is any issues with it.

This is not mean as an actual proposal.

Assumption

This text assumes type parameterized interface default

@smyrman
smyrman / ensure_foo_v1.go
Last active July 14, 2019 17:01
Go 1.13 errors
func EnsureFoo(client jsonrpc.Client, maxRetries int) error {
var backof time.Duration
for retry:= 0; retry < maxRetries; retry++ {
time.Sleep(backof)
_, err := client.Call("foobar.Foo", json.RawMessage(`["bar"]`))
switch errT := err.(type) {
case nil:
return nil
case jsonrpc.Error:
@smyrman
smyrman / Taskfile.yml (docker images)
Last active February 5, 2023 03:32
Taskfile example for templated container builds
## -- build groups --
default:
desc: "alias for all"
deps:
- all
all:
desc: "group for building all container images"
deps:
@smyrman
smyrman / doc.go
Last active October 18, 2017 09:00
rest-layer OpenAPI
// Package openapi provides tools for generating JSON that conforms with the
// OpenAPI specification verison 3. Note that the implementation is minimal,
// and a lot of optional fields have been skipped. Also, the package removes
// leeway and enforces consistency on which fields must be specified as full
// objects and where references must be used instead.
//
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md
package openapi
@smyrman
smyrman / gitweb.conf
Created May 3, 2013 07:17
Sindre's gitweb.conf
$git_temp = "/tmp";
# The directories where your projects are. Must not end with a slash.
our $projectroot = "/srv/git";
$feature{'blame'}{'default'} = [1];
$feature{'blame_incremental_'}{'default'} = [1];
$feature{'avatar'}{'default'} = [1];
$feature{'highlight'}{'default'} = [1];
$feature{'atom'}{'default'} = [1];
@smyrman
smyrman / .lvimrc (Go project)
Last active October 22, 2015 13:47
vimrc file of Sindre Myren
" Set default max line with for all filetypes to 120.
set noexpandtab sw=8 sts=8 ts=8 tw=120
" Set max line width for Git commit to 79.
if &filetype == 'gitcommit'
set tw=79
endif