Skip to content

Instantly share code, notes, and snippets.

@nxnfufunezn
nxnfufunezn / example.md
Created July 3, 2016 08:17 — forked from ericclemmons/example.md
HTML5 <details> in GitHub

Using <details> in GitHub

Suppose you're opening an issue and there's a lot noisey logs that may be useful.

Rather than wrecking readability, wrap it in a <details> tag!

<details>
 <summary>Summary Goes Here</summary>
Registers
Caller-saved Callee-saved
RAX RCX RSP RDI RSI RDX R8 R9 R10 R11 RBP RBX R12 R13 R14 R15
Args: RDI, RSI, RDX, RCX, R8, R9, XMM0–7
Return: RAX
Simple Compile
yasm -f macho64 foo.asm && gcc foo.c foo.o -Wall -Wextra -g -O1
@nxnfufunezn
nxnfufunezn / gist:c769c2c851746af1ad516e4b71a350c3
Created May 16, 2016 06:19 — forked from rygorous/gist:e0f055bfb74e3d5f0af20690759de5a7
A bit of background on compilers exploiting signed overflow
Why do compilers even bother with exploiting undefinedness signed overflow? And what are those
mysterious cases where it helps?
A lot of people (myself included) are against transforms that aggressively exploit undefined behavior, but
I think it's useful to know what compiler writers are accomplishing by this.
TL;DR: C doesn't work very well if int!=register width, but (for backwards compat) int is 32-bit on all
major 64-bit targets, and this causes quite hairy problems for code generation and optimization in some
fairly common cases. The signed overflow UB exploitation is an attempt to work around this.
@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

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 / 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" \
./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 / 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"),
@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):