Skip to content

Instantly share code, notes, and snippets.

@dmotylev
dmotylev / install.sh
Last active August 29, 2015 14:08
dot files: git-free install
curl -Ls http://git.io/... | tar xzs '/dmotylev-dotfiles-[a-f[:digit:]]*/dotfiles/' && dotfiles/bootstrap
@dmotylev
dmotylev / snippet
Created December 11, 2014 16:15
shell snippet
#!/bin/bash
set -o nounset
set -o privileged
set -o errtrace
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
readonly LOG_TS_FMT='+%Y-%m-%d %H:%M:%S'
@dmotylev
dmotylev / jenkins-config-backup
Created December 18, 2014 16:36
Builds a jenkins-config.tar.gz in current directory. The archive includes full JENKINS_HOME but builds/ and workspaces/.
#!/bin/sh
readonly jenkins_data=/var/lib/jenkins
readonly jenkins_data_escaped=$(echo $jenkins_data | sed -E 's/\//\\\//g')
readonly filelist=$(mktemp)
find $jenkins_data |
sed -E "
s/^$jenkins_data_escaped\///;
/^${jenkins_data_escaped}$/d;
@dmotylev
dmotylev / bash_template_engine.sh
Last active August 29, 2015 14:11
simple bash template engine
#!/usr/bin/env bash
if ! [[ ${BASH_VERSINFO[0]} -ge 4 && ${BASH_VERSINFO[1]} -ge 2 ]]; then
echo "$(basename $0): bash version >= 4.2 required"
exit 1
fi
#
# expands {{varname}} to varvalue
#
@dmotylev
dmotylev / latency.txt
Created December 28, 2015 20:31 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@dmotylev
dmotylev / hostnamegen
Last active August 14, 2017 19:31
A random Heroku-like hostname generator (bash)
#!/usr/bin/env bash
# original gist (javascript) https://gist.github.com/afriggeri/1266756
readonly ADJECTIVES=("autumn" "hidden" "bitter" "misty" "silent" "empty" \
"dry" "dark" "summer" "icy" "delicate" "quiet" "white" "cool" "spring" \
"winter" "patient" "twilight" "dawn" "crimson" "wispy" "weathered" "blue" \
"billowing" "broken" "cold" "damp" "falling" "frosty" "green" "long" "late" \
"lingering" "bold" "little" "morning" "muddy" "old" "red" "rough" "still" \
"small" "sparkling" "throbbing" "shy" "wandering" "withered" "wild" "black" \
"young" "holy" "solitary" "fragrant" "aged" "snowy" "proud" "floral" \
"restless" "divine" "polished" "ancient" "purple" "lively" "nameless")
@dmotylev
dmotylev / worm.go
Created April 13, 2018 13:51
Write once read many object
// Provides Write once read many (WORM) primitives
package worm
import (
"sync"
)
// Object could be used to store interface{}
// Object is safe for concurrent usage
type Object struct {
@dmotylev
dmotylev / type_test.go
Last active June 20, 2018 10:47
Go's test func template
func TestType_TestFunc(t *testing.T) {
tests := []struct {
name string
wantErr bool
}{
{"test", false},
}
const wantTest = -1
for testNo, test := range tests {
@dmotylev
dmotylev / main.go
Created January 22, 2019 10:30
service helpers
func WaitShutdownRequest(f func(os.Signal)) {
signals := make(chan os.Signal)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
f(<-signals)
}
func CleanUp(closers ...func()) {
for _, f := range closers {
f()
}
@dmotylev
dmotylev / main.go
Created April 1, 2019 13:57
main.go template for cli tool or server
package main
import (
"context"
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"