Skip to content

Instantly share code, notes, and snippets.

@ukautz
ukautz / main.go
Last active May 25, 2020
Medium > Intro to Go > Full HTTP server
View main.go
// 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 Feb 12, 2020
Benchmark T-Digest implementation Golang
View benchmark_test.go
package tdigest_benchmark
import (
"fmt"
"math/rand"
"testing"
"time"
ajwerner "github.com/ajwerner/tdigest"
caio "github.com/caio/go-tdigest"
View output.md
$ 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 Jul 11, 2019
Does test.benchmem work with CGO?
View foo.go
package foo
import (
"C"
"strings"
)
var testString = strings.Repeat("x", 1024)
func NativeStrings(amount int) {
@ukautz
ukautz / channel_v_vs_r_test.go
Created Jul 9, 2019
Benchmark channel usage with struct values vs struct references
View channel_v_vs_r_test.go
package play
import "testing"
type (
aDataType struct {
A string
B int
C []byte
}
@ukautz
ukautz / go-tool-install.sh
Last active Jul 1, 2019
Install Go tooling from clean docker container
View go-tool-install.sh
#!/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 Feb 10, 2021
Dump LDAP search result as JSON
View README.md

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 Apr 11, 2018
Console helper to set Go(lang) path variables from current directory using `gopath`
View godev.sh
#!/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 Jun 9, 2017
Deploy script on fortrabbit with graceful shutdown
View deploy.php
<?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 Jun 6, 2017
Composer install in sub directory
View README.md

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