Skip to content

Instantly share code, notes, and snippets.

@m-mizutani
m-mizutani / ptree.h
Created August 8, 2011 22:00
Patricia Tree Template in C++
#ifndef __PTREE_H__
#define __PTREE_H__
#include <sys/types.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
@m-mizutani
m-mizutani / rbtree.h
Created August 9, 2011 22:13
Red-Black Tree template in C++
#ifndef __RBTREE_H__
#define __RBTREE_H__
#include <assert.h>
#include <string>
#ifdef DEBUG
#include "debug.h"
#endif
@m-mizutani
m-mizutani / dmsg.h
Created August 9, 2011 22:17
debug message macro in C
#include <time.h>
#include <sys/time.h>
#include <stdarg.h>
#include <stdio.h>
#define dmsg(X, ...) \
do { \
struct tm td; \
struct timeval tv; \
@m-mizutani
m-mizutani / test_sqlite3_blob.py
Created August 19, 2011 03:13
Insert binary data as array.array type to sqlite3 DB as BLOB in python
import sqlite3
import array
a = array.array('B', [3, 1, 2,5,41,44,231,212,0,66,67,68])
b = buffer(a.tostring())
conn = sqlite3.connect ('test.db')
conn.execute ('create table if not exists test (id integer primary key, b blob)')
@m-mizutani
m-mizutani / tscreen.rb
Created August 20, 2011 20:17
brew Formula file for tscreen
require 'formula'
class Tscreen < Formula
url 'http://www.steve.org.uk/Software/tscreen/dist/tscreen-0.4.9.tar.gz'
sha256 'b920f1a96dfa8a390601a8e78fc7ab49d4599f7544e30cfdae5ea0e0aeb0305d'
def install
system "./configure", "--disable-debug", "--prefix=#{prefix}", "--enable-colors256"
system "make install"
end
@m-mizutani
m-mizutani / dpkt_netbios_mdns.py
Created September 2, 2011 09:13
packet dump with pcapy & dpkt in Python
#!/usr/bin/env python
# coding: utf-8
#----------------------------------------------------
# packet capture & decoding
import pcapy
import dpkt
class network_monitor:
def __init__ (self):
@m-mizutani
m-mizutani / dumper.sh
Created September 8, 2011 14:20
tcpdump rotator in shell script
#!/bin/zsh
PID_FILE=$HOME/local/var/run/`basename $0`.pid
NIC=en0
DATA_DIR=$HOME/local/var/data
FNAME_PREFIX="dump"
FILTER="port not 80"
if [ "`id -u`" != "0" ]
then
@m-mizutani
m-mizutani / audio_file_extractor.sh
Created September 13, 2011 14:51
Audio file extractor
#!/bin/sh
if [ $# != 1 ]
then
echo 'syntax)' `basename $0` '<movie>'
exit
fi
target=$1
base=`echo $target | sed -e 's@\.[a-z0-9]*$@@g'`
@m-mizutani
m-mizutani / v8_test.cc
Created October 2, 2011 14:18
v8 Javascript Engine Test
// build) g++ v8_test.cc -o v8_test -lv8
#include <v8.h>
#include <string>
char * js_src =
"function laugh() {"
" print ('HAHAHA'); "
"}; "
"s = append ('echo');"
@m-mizutani
m-mizutani / cond_signal_benchmark.c
Created October 9, 2011 06:27
pthread_cond_signal benchmark
#include <pthread.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
long long TEST_NUMBER ;
typedef struct {
pthread_mutex_t mutex;