Skip to content

Instantly share code, notes, and snippets.

@bvk
bvk / gist:236de6fe34019ed8ccbe75a11379b454
Created Jan 24, 2019
Using rsync with .gitignore files
View gist:236de6fe34019ed8ccbe75a11379b454
#
# 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 / Makefile
Last active Dec 14, 2017
Run any shell command through Make environment
View Makefile
# 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:c5d2919d5ab02f3f01ccc19c42a42880
Created Feb 1, 2017
Resolve a hostname using a different DNS server
View gist:c5d2919d5ab02f3f01ccc19c42a42880
package main
import (
"flag"
"fmt"
"log"
"net"
"github.com/miekg/dns"
)
@bvk
bvk / gist:28c0243016df9a57778f
Created Mar 13, 2016
Docker builds using GNU Autotools build system
View gist:28c0243016df9a57778f
#
# 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:88879332aeca41a7482c
Created Jan 22, 2016
Go like "defer" for C using GCC extensions
View gist:88879332aeca41a7482c
#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 / latency.txt
Created Jan 2, 2016 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
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