Skip to content

Instantly share code, notes, and snippets.

View lichray's full-sized avatar

Zhihao Yuan lichray

View GitHub Profile
@lichray
lichray / quote.c
Created April 13, 2012 06:18
Reliably quote a string as a single argument for /bin/sh.
#include <sys/param.h>
#include <sys/wait.h>
#include <ctype.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@lichray
lichray / cplusplus.xml
Created April 28, 2012 21:55
C++ Reference OpenSearch Plugin
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/" xmlns:os="http://a9.com/-/spec/opensearch/1.1/">
<os:ShortName>C++ Reference</os:ShortName>
<os:Description>Reference of the C++ Language Library</os:Description>
<os:InputEncoding>ISO-8859-1</os:InputEncoding>
<os:Image width="16" height="16">data:image/x-icon;base64,
AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEA
AAABAAD/8/MA/9bYAP7v8gDZxskAy3t+AP/NzgD/5ukA/OTmAP/6+gD5jZIA94uQAP+5ugDnhooA
5oaJAOvS1QDVwMIA/8DBAGlJSgBOMTIA//v+AJxqagDxwsQA/vLzAP66vQC8cHMA/+nqAFowMQD/
+/sA/9zgAMN0dwBsUlEA9oyQAPz3+AD7oqYA7Y2RAOyNkAD/ursA8oiMAP3R1AD94+UA6+fnAP/1
+AD8vb8A287QAOXh4QD/0dMA/uztAOqHiwD86usA4IiLAP/+/wD4rrEA3dnZAP/8/wBtVVYA+8LF
@lichray
lichray / mount_wait.c
Created April 30, 2012 02:39
A kqueue(2) example, listens to VFS mount/umount events.
#include <sys/types.h>
#include <sys/event.h>
#include <sys/mount.h>
#include <stdio.h>
int main() {
int kq = kqueue();
struct kevent ki[1];
@lichray
lichray / patch-charclass.c
Created June 5, 2012 05:03
xterm-279: Allow Chinese/Japanese to be selected as an ASCII word
--- charclass.c.orig 2009-11-05 17:46:15.000000000 -0600
+++ charclass.c 2012-06-05 00:08:48.870241313 -0500
@@ -116,18 +116,8 @@ init_classtab(void)
SetCharacterClassRange(0x200b, 0x27ff, IDENT); /* punctuation and symbols */
SetCharacterClassRange(0x2070, 0x207f, 0x2070); /* superscript */
SetCharacterClassRange(0x2080, 0x208f, 0x2080); /* subscript */
- SetCharacterClassRange(0x3000, 0x3000, BLANK); /* ideographic space */
- SetCharacterClassRange(0x3001, 0x3020, IDENT); /* ideographic punctuation */
- SetCharacterClassRange(0x3040, 0x309f, 0x3040); /* Hiragana */
- SetCharacterClassRange(0x30a0, 0x30ff, 0x30a0); /* Katakana */
@lichray
lichray / patch-VTPrsTbl.c
Created June 7, 2012 23:38
xterm-279: Let XTerm recognize ^P as \E -- help bypassing ISO-2022
--- VTPrsTbl.c~ 2012-04-26 04:04:37.000000000 -0500
+++ VTPrsTbl.c 2012-06-06 21:02:22.242768878 -0500
@@ -105,7 +105,7 @@ CASE_CR,
CASE_SO,
CASE_SI,
/* DLE DC1 DC2 DC3 */
-CASE_IGNORE,
+CASE_ESC,
CASE_IGNORE,
CASE_IGNORE,
@lichray
lichray / valgrind-patch-configure
Created June 27, 2012 22:16
Make valgrind in the freebsd ports compilable with clang.
--- configure~ 2012-06-09 04:40:02.045104538 -0500
+++ configure 2012-04-10 17:22:13.567263417 -0500
@@ -5326,27 +5326,37 @@ gcc_version=`${CC} --version \
| $SED 's/i686-apple-darwin11//' \
| $SED 's/^[^(]*([^)]*) *\([0-9.]*\).*$/\1/'`
+clang_version=`${CC} --version \
+ | head -n 1 \
+ | $SED 's/^.*version *\([0-9.]*\).*$/\1/'`
+
#!/usr/bin/env python
# a solve to http://www.zhihu.com/question/20467075
import random
def gen_seats(n):
ls = range(1, n + 1) * 2
random.shuffle(ls)
return ls
def get_strategies(ls):
@lichray
lichray / patch-src_lib_fcitx-gclient_fcitxclient.c
Created September 16, 2012 14:31
Enable fcitx-glient log for debug build.
--- ./src/lib/fcitx-gclient/fcitxclient.c~ 2012-09-12 08:39:35.000000000 -0500
+++ ./src/lib/fcitx-gclient/fcitxclient.c 2012-09-16 09:21:47.061179876 -0500
@@ -26,9 +26,13 @@
#include "fcitxclient.h"
#include "marshall.h"
+#ifdef _DEBUG
#define fcitx_gclient_debug(...) g_log ("fcitx-client", \
G_LOG_LEVEL_DEBUG, \
__VA_ARGS__)
@lichray
lichray / linux-gtk-bluecurve-theme.fc7.shar
Created December 1, 2012 16:25
Updated x11-themes/linux-gtk-bluecurve-theme, works for linux-f10
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# linux-gtk-bluecurve-theme.fc7
# linux-gtk-bluecurve-theme.fc7/distinfo.i386
# linux-gtk-bluecurve-theme.fc7/Makefile
@lichray
lichray / python_startup.py
Created February 26, 2013 04:34
setenv PYTHONSTARTUP this_file
import atexit
import os
import readline
import rlcompleter
hist_path = os.path.expanduser("~/.python/history")
readline.parse_and_bind("tab: complete")
readline.set_history_length(1000)
if os.path.exists(hist_path):