Skip to content

Instantly share code, notes, and snippets.

@yinyin
yinyin / bxd.c
Created June 5, 2012 08:18
An quick utility to convert binary text (eg: 01010110) into binary file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#if (__APPLE__) || (USE_DARWIN)
#include <libkern/OSByteOrder.h>
#define htobe64(x) OSSwapHostToBigInt64(x)
#else
@yinyin
yinyin / coderunner.py
Created June 26, 2012 05:22
run program with time limit
# -*- coding: utf-8 -*-
import os
import time
import signal
import pwd
_DEFAULT_ENV = {"PATH": "/sbin:/usr/sbin:/bin:/usr/bin", "LANG": "en_US.UTF-8"}
@yinyin
yinyin / redmine2-init.sh
Created June 26, 2012 05:49
An init script for Redmine2 (written for a debian box)
#! /bin/sh
# /etc/init.d/redmine2
### BEGIN INIT INFO
# Provides: redmine2
# Required-Start: $remote_fs $syslog $named $network $time mysql
# Required-Stop: $remote_fs $syslog $named $network mysql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redmine Issue Tracker
@yinyin
yinyin / unit2.py
Created July 8, 2012 04:39
Modified unit2.py for automatic test discovery
#! /usr/bin/env python
# based on the unit2.py from unittest2
# {{{ automatically attach options for discover
import sys
if (1 == len(sys.argv)) or ( (2 == len(sys.argv)) and (sys.argv[1] in ("-v", "--verbose",)) ):
extra_arg = None
if 2 == len(sys.argv):
@yinyin
yinyin / endpoint.php
Created July 25, 2012 17:55
JSONP experiment w/ PHP and jQuery
<?php
header('Content-Type: application/json');
$callback = trim($_GET['callback']);
if(!empty($callback))
{ echo $callback, '('; }
echo '{"status": 0, "tstamp": ', time(), '}';
if(!empty($callback))
{ echo ');'; }
?>
@yinyin
yinyin / json_helper.php
Created July 25, 2012 18:04
JSON(P) generation helper for CodeIgniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// --------
/**
* Dump JSON from array
*
* For each array, an element with key '__json-type-hint' can be attached to hint structure type to
* generator. The value of '__json-type-hint' can be 'array' or 'dict'.
*
@yinyin
yinyin / setup-addon.py
Created August 4, 2012 02:50
a specialized {build,install}_scripts distutil command to perform path variable substitution on installing executable scripts
# -*- coding: utf-8 -*-
import os
import re
from distutils.command.build_scripts import build_scripts as _build_scripts
from distutils.command.install_scripts import install_scripts as _install_scripts
@yinyin
yinyin / squashfs4.2-macosx.patch
Created November 14, 2012 07:31
Patch to make squashfs-tool 4.2 built on Mac OS X
diff -rupN squashfs4.2/squashfs-tools/Makefile squashfs4.2-mac/squashfs-tools/Makefile
--- squashfs4.2/squashfs-tools/Makefile 2011-03-01 04:04:15.000000000 +0800
+++ squashfs4.2-mac/squashfs-tools/Makefile 2012-11-14 15:27:31.000000000 +0800
@@ -104,7 +104,7 @@ UNSQUASHFS_OBJS = unsquashfs.o unsquash-
CFLAGS ?= -O2
CFLAGS += $(EXTRA_CFLAGS) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 \
-D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\"$(COMP_DEFAULT)\" \
- -Wall
+ -DFNM_EXTMATCH=0 -Wall
@yinyin
yinyin / daemonize.pl
Created December 16, 2012 17:18
argument parsing of daemonize.pl
if($opt =~ /^--pid=(.+)$/)
{ $PID = $1; $PID =~ s/\s+$//; }
elsif($opt =~/^--(working-dir|wd)=(.+)$/)
{ $WORKDIR = $2; $WORKDIR =~ s/\s+$//; }
elsif($opt =~/^--(log|terminal-log)=(.+)$/)
{ $TRMLOG = $2; $TRMLOG =~ s/\s+$//; }
elsif($opt =~/^--send-int-before-term=([0-9]+)$/)
{ $SEND_INT_BEFORE_TERM = int($1); }
elsif( ($opt eq '-v') or ($opt eq '--verbose') )
{ $VERBOSE = 1; }
#!/usr/bin/python
""" Parsing timing information of sunrise and sunset from CWB """
import sys
import csv
import re
import pprint