Skip to content

Instantly share code, notes, and snippets.

write some test code
@changtimwu
changtimwu / paramscheck.py
Created December 18, 2010 17:51
a decorator for bottle which checks http query parameters with the applied function's argument spec
import json
from bottle import route, run, request
def params_check():
def decorator(func):
argnames=func.func_code.co_varnames[:func.func_code.co_argcount]
defnames = argnames[ (len(argnames)-len( func.func_defaults )):]
def wrapper(*args, **kwargs):
for argname in argnames:
if argname in request.GET:
#include <stdio.h>
#include <string.h>
static const char *major_tune_strs[2][12]=
{
{"C", "Db", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"},
{"C", "C#", "D", "D#", "E", "F", "Gb", "G", "G#", "A", "A#", "B"},
};
(function (A, w) {
function ma() {
if (!c.isReady) {
try {
s.documentElement.doScroll("left")
} catch (a) {
setTimeout(ma, 1);
return
}
c.ready()
@changtimwu
changtimwu / android_listeners.java
Created September 17, 2011 02:08
how to create listener
/* 1: listener as Activity's internal object. */
public class ContactsInserter extends Activity {
View.OnClickListener onInsert=new View.OnClickListener() {
public void onClick(View v) {
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@changtimwu
changtimwu / compile_jade.js
Created November 4, 2011 11:17
use jade lib to generate a template render function
#!/usr/bin/node
var jade = require('jade');
var fs = require('fs');
var path = require('path');
var compile = function (str) {
options ={ client: true, compileDebug: false};
var fn = jade.compile(str, options);
return fn.toString();
}
@changtimwu
changtimwu / simple_capture.coffee
Created January 9, 2012 09:58
packet buffer binary processing
#global process require exports
sys = require 'util'
pcap = require 'pcap'
require 'buffertools'
if process.argv.length > 4
sys.error "usage: simple_capture interface filter"
sys.error "Examples: "
sys.error ' simple_capture "" "tcp port 80"'
sys.error ' simple_capture eth1 ""'
@changtimwu
changtimwu / timer.coffee
Created January 18, 2012 09:49
nodejs timer example
#usage:
#coffee timer.coffee
#input the following command
# s1000
# e
# s100
# e
# s2000
# e
@changtimwu
changtimwu / example_settings.yml
Created January 19, 2012 08:46
an example setting file in yaml format
#simple key value
ip: 192.168.12.33
dmac: '55:33:44:22:11'
#array
hwifs:
- eth0
- eth1
- en2
@changtimwu
changtimwu / read_yml.coffee
Created January 19, 2012 08:47
An example to demostrate how to use js-yaml
util = require 'util'
fs= require 'fs'
yaml = require 'js-yaml'
# pass the string
fs.readFile 'example.yml', 'utf8', (err, data) ->
if err
console.log 'something wrong', err
return
try