Skip to content

Instantly share code, notes, and snippets.

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
@nxnfufunezn
nxnfufunezn / README.md
Last active August 29, 2015 14:20 — forked from jonhoo/README.md

Distributed Read-Write Mutex in Go

The default Go implementation of sync.RWMutex does not scale well to multiple cores, as all readers contend on the same memory location when they all try to atomically increment it. This gist explores an n-way RWMutex, also known as a "big reader" lock, which gives each CPU core its own RWMutex. Readers take only a read lock local to their core, whereas writers must take all locks in order.

@nxnfufunezn
nxnfufunezn / persistent_pipes_linux.md
Last active September 13, 2015 10:50 — forked from CAFxX/persistent_pipes_linux.md
Persistent pipes/circular buffers for Linux

Persistent "pipes" in Linux

In a project I'm working on I ran into the requirement of having some sort of persistent FIFO buffer or pipe in Linux, i.e. something file-like that could accept writes from a process and persist it to disk until a second process reads (and acknowledges) it. The persistence should be both across process restarts as well as OS restarts.

AFAICT unfortunately in the Linux world such a primitive does not exist (named pipes/FIFOs do not persist

@nxnfufunezn
nxnfufunezn / log10.c
Last active September 13, 2015 10:53 — forked from CAFxX/log10.c
Fast integer log10 in C
#include <stdint.h>
/*
Fast 64bit integer log10
WARNING: calling ilog10c(0) yields undefined behaviour!
On x64 this compiles down to:
pushq %rbp
@nxnfufunezn
nxnfufunezn / test_encoding.py
Created October 26, 2015 04:41
Python Script to test encoding
from flask import after_this_request, request
from cStringIO import StringIO as IO
import gzip
import functools
def gzipped(f):
@functools.wraps(f)
def view_func(*args, **kwargs):
@after_this_request
def zipper(response):
@nxnfufunezn
nxnfufunezn / brotli.py
Last active October 26, 2015 17:11
brotli test
import brotli
def main(request, response):
if "content" in request.GET:
output = request.GET["content"]
else:
output = request.body
output = brotli.compress(output)
headers = [("Content-type", "text/plain"),
./mach cargo-update -p brotli --precise 0.3.17
components/servo
thread '<main>' panicked at 'index 0 and/or 8 in `0.3.17` do not lie on character boundary', ../src/libcore/str/mod.rs:1284
@nxnfufunezn
nxnfufunezn / incbin.c
Created December 31, 2015 16:30 — forked from mmozeiko/incbin.c
Include binary file with gcc
#include <stdio.h>
#define STR2(x) #x
#define STR(x) STR2(x)
#define INCBIN(name, file) \
__asm__(".section .rodata\n" \
".global incbin_" STR(name) "_start\n" \
".type incbin_" STR(name) "_start, @object\n" \
".balign 16\n" \

Keybase proof

I hereby claim:

  • I am nxnfufunezn on github.
  • I am nxnfufunezn (https://keybase.io/nxnfufunezn) on keybase.
  • I have a public key whose fingerprint is 9369 D7F4 0F45 BBB3 6C27 C45A AFC9 CF33 B178 6FD6

To claim this, I am signing this object:

@nxnfufunezn
nxnfufunezn / latency.markdown
Created March 10, 2016 06:40 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs