Skip to content

Instantly share code, notes, and snippets.

@oxnz
oxnz / free.c
Last active August 29, 2015 13:56
darwin system utility
#include <stdio.h>
#include <sys/sysctl.h>
#include <mach/host_info.h>
#include <mach/mach_host.h>
#include <mach/task_info.h>
#include <mach/task.h>
void usage(int verbose) {
printf("Usage:\n");
@oxnz
oxnz / server.cpp
Created February 5, 2014 02:23
a simple tcp server
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s port\n", argv[0]);
return -1;
}
#!/usr/bin/perl
# Description: http://daringfireball.net/2010/08/open_urls_in_safari_tabs
# License: See below.
# http://gist.github.com/507356
use strict;
use warnings;
use URI::Escape;
LDFLAGS = -framework IOKit -framework ApplicationServices
test: test.m
\documentclass[a4paper, 12pt]{book}
\usepackage[colorlinks,linkcolor=blue,anchorcolor=blue,citecolor=green,CJKbookmarks=true]{hyperref}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{xeCJK}
\setCJKmainfont[BoldFont={STHeiti},ItalicFont={STKaiti}]{STSong}
\setmainfont{Times New Roman}
\setCJKsansfont[BoldFont={STHeiti}]{STXihei}
\setsansfont{Helvetica}
\setCJKmonofont{STFangsong}
\setmonofont{Courier New}
#include <stdio.h>
#include <stdlib.h>
/* The following include files for the network interface. */
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@oxnz
oxnz / manifest.xml
Created October 1, 2013 17:39
Autostart an application at bootup
in AndroidManifest.xml (application-part):
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
@oxnz
oxnz / daemon.py
Created October 1, 2013 09:58
daemonize
#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method
@oxnz
oxnz / tinep2p.py
Created September 26, 2013 12:54
#Python语言: 传说中只用了十五行Python语句的P2P客户端/服务端
#zz from http://www.exonsoft.com/~kochin/TinyP2P/tinyp2p.html
# tinyp2p.py 1.0 (documentation at http://freedom-to-tinker.com/tinyp2p.html)
# (C) 2004, E.W. Felten
# license: http://creativecommons.org/licenses/by-nc-sa/2.0
# Annotated by Kochin Chang, Jan. 2005