Skip to content

Instantly share code, notes, and snippets.

@Merovius
Merovius / go-birdseye.md
Created April 2, 2019 14:12
A birdseye view of Go

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

@Merovius
Merovius / client.go
Created September 19, 2013 18:59
Dbus minimal example in go, rudimentary implementation of http://www.galago-project.org/specs/notification/0.9/
package main
import (
"github.com/guelfey/go.dbus"
)
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
@Merovius
Merovius / fdg.js
Created May 16, 2019 15:09
Force-directed graph drawing
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");
////////////////////////////////////////////////////////////////////////////
// Program: dbab-svr
// Purpose: Pixel Server in Go
// Authors: Tong Sun (c) 2019, All rights reserved
////////////////////////////////////////////////////////////////////////////
package main
import (
"bufio"
@Merovius
Merovius / breaklabel.go
Created August 20, 2019 13:24
break label experiment
// 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,
@Merovius
Merovius / new-jekyll-post.sh
Last active September 28, 2019 02:12
Automatically create a jekyll blogpost from a template. An editor is launched to edit the post, after it exits, the current date and time is added to the preamble and it is saved under a filename containing date and mangled article title into _posts. Optionally launches a jekyll server while editing the draft and commits the resulting blogpost.
#!/bin/sh
# The file extension to use for the post
FMT="markdown"
# Maximum length title used in filename
MAXLEN=32
# Wether or not to start a jekyll server for the draft
START_JEKYLL=true
# Wether to automatically commit the post or not
AUTOCOMMIT=true
package main
import (
"context"
"fmt"
"log"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/examples/helloworld/helloworld"
@Merovius
Merovius / README.md
Created July 16, 2021 22:55
MergeSlice benchmarks

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

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