Skip to content

Instantly share code, notes, and snippets.

View sort_test.go
package main
import (
"encoding/base64"
"math/rand"
"testing"
"x/esort"
"golang.org/x/exp/constraints"
@Merovius
Merovius / callsrc.go
Created September 29, 2022 07:49
package callsrc
View callsrc.go
// Package callsrc helps enforcing that a function is only called in certain contexts.
package callsrc
import (
"io"
"os"
"runtime"
"strings"
)
@Merovius
Merovius / README.md
Created July 16, 2021 22:55
MergeSlice benchmarks
View README.md

The post Go is not C, so there is not an extreme fast way to merge slices alleges a performance problem with Go's model of zeroing memory on allocation, in cases where it might not be needed. The methodology is

  • Run a benchmark that merges some slices, by makeing one of the appropriate size and copying the individual slices over
  • Run a benchmark that zeros a slice of the appropriate slice
  • Subtract the two numbers and call it the "overhead of zeroing"

I have some trouble with that methodology. For one, it assumes that the zeroing

View grpc-repro.go
package main
import (
"context"
"fmt"
"log"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/examples/helloworld/helloworld"
@Merovius
Merovius / breaklabel.go
Created August 20, 2019 13:24
break label experiment
View breaklabel.go
// Copyright 2019 Axel Wagner
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
View foo.go
////////////////////////////////////////////////////////////////////////////
// Program: dbab-svr
// Purpose: Pixel Server in Go
// Authors: Tong Sun (c) 2019, All rights reserved
////////////////////////////////////////////////////////////////////////////
package main
import (
"bufio"
@Merovius
Merovius / fdg.js
Created May 16, 2019 15:09
Force-directed graph drawing
View fdg.js
function Graph(div, edges, update) {
let g = this;
let c = document.createElement("canvas");
c.width = '800';
c.height = '400';
c.style.background = '#ffffff';
div.appendChild(c);
div.appendChild(document.createElement("br"));
let runSim = document.createElement("input");
@Merovius
Merovius / go-birdseye.md
Created April 2, 2019 14:12
A birdseye view of Go
View go-birdseye.md

When we talk about "Go", depending on context, we can mean very different things. This is my attempt at providing the furthest possible overview of the language and ecosystem and to link to the relevant documentation about how each part fits together. So, let's dive in:

The Go programming language

The bottom turtle is Go, the programming language. It defines the format and meaning of source code and the authoritative source for how it works is [the Go

View go.mod
module github.com/gobuffalo/buffalo
require (
github.com/dgrijalva/jwt-go v0.0.0-20180308231308-06ea1031745c
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e
github.com/fatih/color v1.7.0
github.com/fatih/structs v1.0.0
github.com/fsnotify/fsnotify v1.4.7
github.com/gobuffalo/envy v1.6.2
github.com/gobuffalo/packr v1.11.0
@Merovius
Merovius / defence.go
Created February 25, 2018 16:22
tiny tool to extract codeblocks from markdown
View defence.go
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
)