Skip to content

Instantly share code, notes, and snippets.

@sanpingz
sanpingz / README-Template.md
Created September 17, 2019 09:06 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@sanpingz
sanpingz / buildsqlite.sh
Last active December 1, 2016 09:32 — forked from Wevah/buildsqlite.txt
Build SQLite dylib
clang -dynamiclib -Os -Wl,-install_name,@rpath/libsqlite3.dylib -mmacosx-version-min=10.10 -o libsqlite3.dylib sqlite3.c
@sanpingz
sanpingz / monitor.py
Last active August 29, 2015 14:10
Performance measurement
#!/usr/bin/env python
__author__ = 'sanpingz'
__doc__ = """The default unit for bandwidth and disk read/write speed are MBytes/s"""
import time
import socket
import pprint
import argparse
import json
@sanpingz
sanpingz / function_cache.py
Last active August 29, 2015 14:10
function cache
__author__ = 'sanpingz'
__doc__ = '''Fucntion cache based on decorator, support expire and args'''
import time
cache = dict()
def cached(expire=0):
def _deco(func):
def __deco(*args, **kwargs):
@sanpingz
sanpingz / enum.py
Created May 25, 2013 15:36
模拟Enum
class Animal:
DOG = 1
CAT = 2
assert DOG == 1
assert CAT == 2
class Enum(set):
def __getattr__(self, name):
if name in self:
return name
@sanpingz
sanpingz / count.py
Created May 25, 2013 09:41
unicode字符计数
#!/usr/bin/env python
#-*- coding:utf8 -*-
import re
import urllib
def counter(url, start, end):
p = urllib.urlopen(url).read().decode('utf8')
art = r'(?s)(?=%s).*?(?<=%s)' % (start, end)
article = re.findall(art, p)[0]
# print article
@sanpingz
sanpingz / comments.cpp
Last active December 17, 2015 16:08
C++ comments
#include <stdio.h>
int main(){
/**** 1. backslash-newline ****/
int a = 1;
//some comments \
a++;
printf("%d\n", a);
@sanpingz
sanpingz / bc_grep.py
Last active December 17, 2015 15:09
Static code analysis
#!/usr/bin/env python
"""Static code analysis for C/C++,
Grep out the bad codes in the C/C++ file,
The premise is that codes were executable.
Usage: bc_grep <C/C++ file>/<C/C++ dir> <-s> <-p>
'-s' is optional, means simple. Defalut will display bad comments detail.
'-p' is optional, means the first arg is a file with dirs or files list in it"""
__author__ = 'sanpingz (sanping.zhang@alcatel-lucent.com)'
import re
@sanpingz
sanpingz / .vimrc
Last active December 17, 2015 12:29
vim配置文件(linux)
set nocompatible
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
@sanpingz
sanpingz / custom.js
Created May 16, 2013 14:01
菜单多级联动
$(function(){
var nav = $('#nav li'),
sub_nav = nav.find('.sub-nav');
nav.on({
'mouseover':function(e){
// console.log($(e.target));
console.log($(e.currentTarget));
// console.log($(e.this));
$(e.currentTarget)