Skip to content

Instantly share code, notes, and snippets.

View wcang's full-sized avatar
🐴
Horsing around

Ang Way Chuang wcang

🐴
Horsing around
View GitHub Profile
@wcang
wcang / mldstd.c
Created May 8, 2013 17:28
Quick tryout of state design pattern for MLD router state transition written in C
/* Implementation of state design pattern for MLD router state transition
* (RFC 2710) using C
*/
#include <stdio.h>
#include <stdbool.h>
struct mld_state {
struct mld_ctx * ctx;
void (*init)(struct mld_state *, struct mld_ctx *);
void (*recv_query)(struct mld_state *, bool lower);
@wcang
wcang / mldstd.py
Created May 8, 2013 16:23
Quick tryout of state design pattern for MLD router state transition
#implementation of state design pattern for MLD router state transition
#(RFC2710)
import time
class NonQuerier:
def __init__(self, ctx):
print "In non-querier"
print "Start other querier timeout"
self.ctx = ctx
self.timeout = time.time()
@wcang
wcang / chroot.py
Created April 17, 2013 17:00
Demo code to try out chroot using python context manager
import os
import sys
import shutil
class chroot:
def __init__(self, root_dir):
self.root_dir = root_dir
def __enter__(self):
self.real_root = os.open("/",os.O_RDONLY)
@wcang
wcang / cd.py
Created April 17, 2013 16:23
Sample code to try out python's context manager.
import os
class cd:
def __init__(self, path):
print "constructor"
self.dest = path
self.origin = os.getcwd()
def __enter__(self):
os.chdir(self.dest)
@wcang
wcang / tee.py
Created April 6, 2013 06:10
Dirty and ugly hack to duplicate stdout stream to a file. This thing sort of acts like unix's tee program. Be careful as this only overwrites several file functions
'''
Dirty and ugly hack to duplicate stdout stream to a file
Be careful as this only overwrites several file functions
This thing sort of acts like unix's tee program
Ang Way Chuang <[email protected]>
Feel free to use, modify and distribute. No warranty and no restriction
'''
import sys