Skip to content

Instantly share code, notes, and snippets.

@dmotylev
dmotylev / macos-tmux-256color.md
Created April 20, 2021 16:23 — forked from bbqtd/macos-tmux-256color.md
Installing tmux-256color for macOS

Installing tmux-256color for macOS

  • macOS 10.15.5
  • tmux 3.1b

macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.

The Fast Blazing Solution

Instead of tmux-256color, use screen-256color which comes with system. Place this command into ~/.tmux.conf or ~/.config/tmux/tmux.conf(for version 3.1 and later):

@dmotylev
dmotylev / worker_pool.go
Last active August 27, 2020 16:26
golang's simple worker pool
package internal
import "sync/atomic"
type worker struct {
jobs chan func()
done chan struct{}
}
func newWorker() *worker {
@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"
@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 / 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 / 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 / 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 / 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 / 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 / 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;