Skip to content

Instantly share code, notes, and snippets.

@ukautz
ukautz / main.go
Last active May 25, 2020 17:26
Medium > Intro to Go > Full HTTP server
// returns a `200 OK` response with the body `Hello World` to any incoming request
package main
import (
"fmt"
"net/http"
)
func helloWorld(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello World"))
@ukautz
ukautz / benchmark_test.go
Last active February 12, 2020 10:15
Benchmark T-Digest implementation Golang
package tdigest_benchmark
import (
"fmt"
"math/rand"
"testing"
"time"
ajwerner "github.com/ajwerner/tdigest"
caio "github.com/caio/go-tdigest"
$ for i in seq 1 3; do go test -bench=. -benchtime=5s; echo; done
goos: linux
goarch: amd64
pkg: github.com/Scout24/go-observability/.local
BenchmarkCallWithoutSlice-4    	100000000	        76.8 ns/op
BenchmarkCallWithSlice-4       	100000000	        77.1 ns/op
BenchmarkCallWithSliceCopy-4   	100000000	        76.4 ns/op
PASS
ok  	github.com/Scout24/go-observability/.local	23.277s
@ukautz
ukautz / foo.go
Created July 11, 2019 14:05
Does test.benchmem work with CGO?
package foo
import (
"C"
"strings"
)
var testString = strings.Repeat("x", 1024)
func NativeStrings(amount int) {
@ukautz
ukautz / channel_v_vs_r_test.go
Created July 9, 2019 12:37
Benchmark channel usage with struct values vs struct references
package play
import "testing"
type (
aDataType struct {
A string
B int
C []byte
}
@ukautz
ukautz / go-tool-install.sh
Last active July 1, 2019 07:49
Install Go tooling from clean docker container
#!/bin/bash
if [ $# != 1 ]; then
echo "Usage: $0 <golang-package>"
echo " for example:"
echo " $0 github.com/gobuffalo/packr/packr"
exit 1
fi
docker run --rm \
@ukautz
ukautz / README.md
Last active February 10, 2021 12:30
Dump LDAP search result as JSON

What can you do with ldapsearch outputs? Not much. With JSON, though ..

# from LDAP search tool ...
ldapsearch -h 127.0.0.1 -p 10389 \
	-D "cn=me,ou=Acme,dc=local" -w 'mypa$$w00t" \
	-b "ou=machines,ou=Acme,dc=local" \
	-s sub "(objectclass=machine)"
@ukautz
ukautz / godev.sh
Last active April 11, 2018 09:16
Console helper to set Go(lang) path variables from current directory using `gopath`
#!/bin/bash
#---------------
#
# Installation:
# $ curl -Lo ~/.godev http://tiny.cc/godev
# $ echo "source ~/.godev" >> ~/.$(basename $SHELL)rc
#
# Usage:
# # Tries to determine go workspace directory, then
# # exports it into GOPATH environment variable
@ukautz
ukautz / deploy.php
Last active June 9, 2017 10:47
Deploy script on fortrabbit with graceful shutdown
<?php
declare(ticks = 1);
// Your graceful shutdown handler
function exitGracefully($signal) {
// do stuff, then end with exit code 0, so that the deploy can continue
// or exit with non-zero code, so that the deploy aborts
echo "Shutting down gracefully\n";
exit(0);
@ukautz
ukautz / README.md
Created June 6, 2017 10:00
Composer install in sub directory

Assumes that path/to/subdir is directory containing composer.json and composer.lock files.