Skip to content

Instantly share code, notes, and snippets.

View mintisan's full-sized avatar

Jinhui-Lin mintisan

View GitHub Profile
@mintisan
mintisan / crc-ccitt.c
Last active August 29, 2015 14:07
crc_ccitt from Linux Kernel
#include "crc-ccitt.h"
// From : http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/crc-ccitt.h?v=2.6.11.8#L11
static u16 crc_ccitt_byte(u16 crc, const u8 c)
{
return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
}

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

@mintisan
mintisan / coroutine3.c
Created April 19, 2015 11:52
Coroutines in C with Arbitrary Arguments
/**
* From
* http://250bpm.com/blog:48
*
**/
#include <stdio.h>
#include <setjmp.h>
#include "stdlib.h"
@mintisan
mintisan / coroutine2.c
Created April 19, 2015 12:00
Tony Finch - Coroutines in less than 20 lines of standard C
/**
* From
* http://fanf.livejournal.com/105413.html
**/
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
@mintisan
mintisan / coroutine.h
Created April 19, 2015 12:03
Coroutines in C
/* coroutine.h
*
* Coroutine mechanics, implemented on top of standard ANSI C. See
* http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html for
* a full discussion of the theory behind this.
*
* To use these macros to define a coroutine, you need to write a
* function that looks something like this.
*
* [Simple version using static variables (scr macros)]
@mintisan
mintisan / latency.txt
Created November 2, 2015 14:24 — 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
@mintisan
mintisan / classify_file_type_in_current_dir.py
Created January 25, 2016 16:05
classify specific file type into a txt within current directory
# -*- coding: utf-8 -*-
import os
import re
def classify_file_type_in_current_dir(file_name, file_type):
f = open(file_name,'wb')
for root, dirs, files in os.walk(os.getcwd(), topdown=True):
for name in files:
@mintisan
mintisan / buttondown.css
Created February 18, 2016 16:50 — forked from ryangray/buttondown.css
A clean, minimal CSS stylesheet for Markdown, Pandoc and MultiMarkdown HTML output.
/*
Buttondown
A Markdown/MultiMarkdown/Pandoc HTML output CSS stylesheet
Author: Ryan Gray
Date: 15 Feb 2011
Revised: 21 Feb 2012
General style is clean, with minimal re-definition of the defaults or
overrides of user font settings. The body text and header styles are
left alone except title, author and date classes are centered. A Pandoc TOC
@mintisan
mintisan / file_name_prefix_add.py
Last active June 25, 2016 06:38
add a specific prefix for all files within current directory
#-*- coding: utf-8 -*-
import os
import numpy as np
import walkdir as wd
prefix = 'pre-'
file_info_type = np.dtype({
'names': ['dir','name'],
@mintisan
mintisan / file_name_strip_modify.py
Created June 25, 2016 06:39
modify split in file_name
#-*- coding: utf-8 -*-
import os
import numpy as np
import walkdir as wd
file_info_type = np.dtype({
'names': ['dir','name'],
'formats':['S100','S100']
})