Skip to content

Instantly share code, notes, and snippets.

View w32zhong's full-sized avatar
⛹️
Trying to keep up.

Wei w32zhong

⛹️
Trying to keep up.
View GitHub Profile

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

@w32zhong
w32zhong / graph.pdf
Last active August 29, 2015 14:11
lpd algorithm dev
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@w32zhong
w32zhong / main.c
Created January 10, 2015 05:32
tokyo cabinet B+ tree multi-value example
// char *str; size_t size;
// FILE *f = open_memstream(&str, &size);
// tex_tr_print(parser_root, f);
// fclose(f);
// printf("str=\n%s||size=%ld\n", str, size);
// free(str);
#include <tcutil.h>
#include <tcbdb.h>
@w32zhong
w32zhong / bb1.txt
Created January 6, 2016 01:10 — forked from dapangmao/bb1.txt
Bloomberg 全体展览
【===========算法============】
【*****leetcode/lintcode*****】
same tree, Binary tree inorder iterator, inorder & postorder traverse BST, binary tree level order traversal(print指定level的binary tree), tree upside down, add next to every tree node, Convert Sorted Array to BST, binary tree的maxSumPath, reverse linkedlist, linkedlist输出倒数K个node的值, linked list取中值, linked list做减法/加法(反序), valid BST, linkedlist找merge point, copy linkedlist with random pointer, flatten BST to linkedlist(把BST替换为2Dlinkedlist,本质不变), depth, interseciton of linked list(一个一步一个多步是否可以(复杂度高)) LRUCache, upside down, recover binary tree from inorder and preorder,
word search I, min stack, stock transaction I(buy date is needed) & II, two sum, subset, unique paths II, merge two/k sorted array/linked list, Find kth largest number(quickselect, array partition), sort colors, remove duplicate from a sorted array, search in sorted rotated array(binary search), search for a range and delete it in array, next permutation, find peak element(一个先降后升的数组,怎么在这个数组中找到
@w32zhong
w32zhong / jieba-position-tag.py
Created April 21, 2016 22:33
get search term tokens with position and tag info
#encoding=utf-8
from jieba.posseg import POSTokenizer
import sys
import jieba
utf8_str = "其实,工信处女干事microsoft每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作"
posseg_tk = None
def cjieba_init():
global posseg_tk
#include <stdio.h>
#include <Python.h>
#include <string.h>
/////////////////////////
//pFunc = PyObject_GetAttrString(pModule, "myjieba_p");
//pArgs = PyTuple_New(1);
//pValue = PyUnicode_FromString(txt);
//PyTuple_SetItem(pArgs, 0, pValue);
//PyObject_CallObject(pFunc, pArgs);
var minisiteUrl = 'http://www.wandoujia.com/campaign/pizzahut/';
var UTM = {
'weibo': '?utm_source=weibo&utm_medium=sns&utm_campaign=pizzahut',
'wechatFriend': '?utm_source=wechatFriend&utm_medium=sns&utm_campaign=pizzahut',
'wechatTimeline': '?utm_source=wechatTimeline&utm_medium=sns&utm_campaign=pizzahut',
// 扫描站内二维码的回流
'qrcode': '?utm_source=qrcode&utm_medium=minisite&utm_campaign=pizzahut'
};
@w32zhong
w32zhong / c99.l
Created May 16, 2016 19:38 — forked from codebrainz/c99.l
C99 Lex/Flex & YACC/Bison Grammars
D [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E ([Ee][+-]?{D}+)
P ([Pp][+-]?{D}+)
FS (f|F|l|L)
IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))
%{
#include <stdio.h>
@w32zhong
w32zhong / simple-zlib.c
Created July 7, 2016 06:39
simple zlib string compress/decompress example
/* compile with:
* gcc simple-zlib.c -lz
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#undef N_DEBUG
@w32zhong
w32zhong / miller_rabin.c
Created November 20, 2017 07:45
primality_test
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
void rand_init()
{
unsigned ticks;
struct timeval tv;
gettimeofday(&tv, NULL);
ticks = tv.tv_sec + tv.tv_usec;