Skip to content

Instantly share code, notes, and snippets.

@bvk
bvk / latency.txt
Created January 2, 2016 21:20 — 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
@bvk
bvk / gist:88879332aeca41a7482c
Created January 22, 2016 22:27
Go like "defer" for C using GCC extensions
#define defer_(x) do{}while(0); \
auto void _dtor1_##x(); \
auto void _dtor2_##x(); \
int __attribute__((cleanup(_dtor2_##x))) _dtorV_##x=69; \
void _dtor2_##x(){if(_dtorV_##x==42)return _dtor1_##x();};_dtorV_##x=42; \
void _dtor1_##x()
#define defer__(x) defer_(x)
#define defer defer__(__COUNTER__)
@bvk
bvk / gist:28c0243016df9a57778f
Created March 13, 2016 05:13
Docker builds using GNU Autotools build system
#
# Save these rules in GNUmakefile in the configure.ac file directory.
#
# If user doesn't specify anything, pick a default docker image.
DOCKER_IMAGE ?= builder-ubuntu
# Bind mounts when running the docker image. Users can add more by defining
# DOCKER_BIND_OPTS in the command-line.
override DOCKER_BIND_OPTS += -v /home:/home
@bvk
bvk / gist:c5d2919d5ab02f3f01ccc19c42a42880
Created February 1, 2017 21:13
Resolve a hostname using a different DNS server
package main
import (
"flag"
"fmt"
"log"
"net"
"github.com/miekg/dns"
)
@bvk
bvk / Makefile
Last active December 14, 2017 21:57
Run any shell command through Make environment
# The following section enables users to execute arbitrary commands
# under Makefile environment. Users are expected run commands with
# 'make run' prefix. For example,
#
# $ make run go env
#
# Users can pass command-line options as follows:
#
# $ make run -- ls -l
@bvk
bvk / gist:236de6fe34019ed8ccbe75a11379b454
Created January 24, 2019 19:02
Using rsync with .gitignore files
#
# Rsync a git repository without .git directory, excluding files as per .gitignore
# -- as if, the target directory is a checkout without .git directory.
#
rsync -azP --delete --delete-excluded --filter=":- .gitignore" --exclude .git/ src/dir/path/ user@host:/dst/dir/path/
#
# Rsync a git repository including the .git directory, excluding files as per
# .gitignore -- as if, the target directory is a clone.
#
@bvk
bvk / width.go
Created January 12, 2024 11:44 — forked from eNV25/width.go
`wcwidth` implementation for Go. Uses the `unicode` and `golang.org/x/text/width` packages.
package textwidth
import (
"unicode"
"golang.org/x/text/width"
)
// IsComb returns true if r is a Unicode combining character. Alias of:
//