Skip to content

Instantly share code, notes, and snippets.

View itsyarkee's full-sized avatar

Yarkee Chou itsyarkee

View GitHub Profile
@itsyarkee
itsyarkee / decorator_cache.py
Created September 30, 2013 03:57
Use decorate to maintain a memory cache.
#-*-coding:utf-8-*-
"""
Use decorate to maintain a memory cache.
"""
def cache_c(fn):
cache = {}
miss = None
def wrapper(*args, **kwargs):
result = cache.get(args, miss)
@itsyarkee
itsyarkee / longlong2str.c
Created September 17, 2013 02:44
convert long long to string in C
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* strfromlonglong(long long value){
char buf[32], *p;
unsigned long long v;
v = (value < 0) ? -value: value;
p = buf + 31;
@itsyarkee
itsyarkee / testhelp.c
Created September 4, 2013 03:03
This is a really minimal testing framework for C. (Referenced from redis source code)
/* This is a really minimal testing framework for C.
*
* Example:
*
* test_cond("Check if 1 == 1", 1==1)
* test_cond("Check if 5 > 10", 5 > 10)
* test_report()
*/
#include<stdio.h>
@itsyarkee
itsyarkee / func_cost_time.py
Created September 4, 2013 02:41
A decorator used to calculate the cost time of functions.
#!/usr/bin/env python
#-*-coding:utf-8-*-
"""
A decorator used to calculate the cost time of functions.
"""
import time
from functools import wraps