Skip to content

Instantly share code, notes, and snippets.

View narqo's full-sized avatar
🌕
Berlin, +10°

Vladimir Varankin narqo

🌕
Berlin, +10°
View GitHub Profile
@narqo
narqo / callback_test.go
Last active August 28, 2018 20:06
Rename struct's fields while keep supporting old JSON data
package callback_test
import (
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
)
@narqo
narqo / main.go
Last active July 27, 2018 09:29
test worker+limiter with antiburst and gracesful shutdown
package main
import (
"context"
"io"
"log"
"net/http"
"os"
"os/signal"
"time"
#!/usr/bin/env sh
# Usage:
# > to_deploy.sh <branch> <base_branch>
branch=${1:-HEAD}
base=${2:-"origin/master"}
declare -r mains=$(go list -json ./... | jq --compact-output '. | select(.Name == "main") | {ImportPath: .ImportPath, Deps: .Deps}')
declare -r changed=($(git diff --name-only ${base}...${branch} \
goos: darwin
goarch: amd64
pkg: test-sort
BenchmarkSort/setsize_10/sort-4 5000000 295 ns/op 32 B/op 1 allocs/op
BenchmarkSort/setsize_10/slice-4 3000000 598 ns/op 112 B/op 3 allocs/op
BenchmarkSort/setsize_100/sort-4 200000 8279 ns/op 32 B/op 1 allocs/op
BenchmarkSort/setsize_100/slice-4 100000 13276 ns/op 112 B/op 3 allocs/op
BenchmarkSort/setsize_1000/sort-4 10000 165268 ns/op 32 B/op 1 allocs/op
BenchmarkSort/setsize_1000/slice-4 10000 209613 ns/op 112 B/op 3 allocs/op
BenchmarkSort/setsize_10000/sort-4 1000 2226969 ns/op 32 B/op 1 allocs/op

Keybase proof

I hereby claim:

  • I am narqo on github.
  • I am varankinv (https://keybase.io/varankinv) on keybase.
  • I have a public key ASDLvr5auhcBxHjWLG42GyA8KvjSp9CXeXPUdkYvtMKD5go

To claim this, I am signing this object:

| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
| now is a |
| great time to |
| turn on your |
| 2-factor auth |
| ________|
(\__/) ||
(•ㅅ•) ||
/   づ
@narqo
narqo / backoff.go
Last active October 26, 2022 09:50
Go by examples
// Backoff is a simple backoff implementation.
type Backoff struct {
MaxAttempts int
Backoff func(int) time.Duration
attempts int
err error
nextCh chan struct{}
}
var ErrMaxAttemptsReached = errors.New("max attempts reached")
@narqo
narqo / Makefile
Created August 27, 2017 00:23
Makefile for general Go project
NAME := myapp
GO := go
LDFLAGS :=
GOFLAGS :=
TESTFLAGS :=
INSTALL := install
bindir := /usr/local/bin
GITSHA := $(shell git rev-parse --short HEAD)
@narqo
narqo / gist:fa7394f127004b964f7da42ffe604388
Created July 1, 2017 11:30
How string's split works across the languages
% node -p '",,,1,,,".split(",")'
< [ '', '', '', '1', '', '', '' ]
% python -c 'a = ",,,1,,,".split(","); print(a);'
< ['', '', '', '1', '', '', '']
//go
import ("log"; "strings")
a := strings.Split(",,,1,,,", ",")
log.Printf("%q", a)
@narqo
narqo / Dockerfile
Created April 22, 2017 19:39
Example of multi-stage build Dockerfile, introduced in docker v17.05.0
# Requires docker >= v17.05.0-ce-rc1
# See http://blog.alexellis.io/mutli-stage-docker-builds/
# Usage:
# > docker build -t syseng-exporter .
FROM golang:1.8 AS go-builder
WORKDIR /go/src/syseng_exporter
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o syseng_exporter .