Skip to content

Instantly share code, notes, and snippets.

View achille-roussel's full-sized avatar

Achille achille-roussel

View GitHub Profile
@achille-roussel
achille-roussel / go-vendor-add-submodules.sh
Last active July 20, 2016 07:04
Go: add github vendor submodules
# Run in the root directory of a go package to list all direct github dependencies
# and create git submodules for them in the vendor directory.
for package in $(
go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | grep github.com | cut -d/ -f1-3 | grep -v $(go list .) | uniq
)
do
git submodule add https://$package vendor/$package
done
@achille-roussel
achille-roussel / go-inline-interface.go
Created August 12, 2016 19:23
Go Inline Interfaces
func errorTypeOf(err error) errorType {
if err == nil {
return errorNone
}
switch e := err.(type) {
case interface {
Timeout() bool
}:
if e.Timeout() {
terraform console
> 100 * 0.5
0
@achille-roussel
achille-roussel / benchmark_ksuid_gzip_snappy.go
Created September 28, 2017 16:48
Benchmark comparing performances of compressing and decompressing slices of KSUIDs using gzip and snappy.
package main
import (
"bytes"
"compress/gzip"
"reflect"
"testing"
"time"
"unsafe"
@achille-roussel
achille-roussel / Makefile.99
Created March 14, 2019 15:59
The 99% Makefile
deps := go.mod
sources := \
$(wildcard ./cmd/demo/*.go) \
$(wildcard ./*.go)
./demo: $(deps) $(sources)
GOOS=linux go build ./cmd/demo/
./demo.tar.gz: ./demo
@achille-roussel
achille-roussel / bench.txt
Created July 25, 2019 02:26
Benchmark: Static vs Reflect vs Unsafe
goos: darwin
goarch: amd64
BenchmarkAppend/Static 50000000 24.5 ns/op
BenchmarkAppend/Reflect 20000000 72.1 ns/op
BenchmarkAppend/Unsafe 30000000 43.7 ns/op
PASS
ok _/tmp 4.135s
@achille-roussel
achille-roussel / gist:6d512e69fc1471ef9584e520eae8617c
Created December 9, 2022 18:37
kafka-go record batch ideas
type Record struct {
Key []byte
Value []byte
}
func (b *RecordBatch) Close() error { ... }
func (b *RecordBatch) ReadRecords(records []Record) (int, error) { ... }
@achille-roussel
achille-roussel / goroutines.go
Last active April 7, 2023 02:40
Detect number of goroutines in different state
package main
import (
"fmt"
"runtime"
"strings"
"time"
)
func main() {
@achille-roussel
achille-roussel / go1.22rc1.md
Last active January 29, 2024 22:50
Go 1.22 rc1 installation to enable the range functions experiment

This file describes how to install Go 1.22 and enable the range functions experimental feature.

Go has standard instructions for managing multiple installations at https://go.dev/doc/manage-install, this document focuses on how to install Go 1.22 rc1 to enable the range functions experiment.

💡 These instructions are only useful until Go 1.22 is officially released (the target is February 2024)

💡 Go 1.22 rc2 has now been released, these instructions are still valid, simply replace rc1 with rc2 to adapt (e.g., https://pkg.go.dev/golang.org/dl/go1.22rc2)

Installing Go 1.22 rc1

@achille-roussel
achille-roussel / custom_future_asyncio.py
Last active June 4, 2024 00:16
Python: custom futures integrating with asyncio event loops
import asyncio
from types import coroutine
@coroutine
def future(value):
yield value
@coroutine
def task(coro):
for item in coro.__await__():