Skip to content

Instantly share code, notes, and snippets.

View lichray's full-sized avatar

Zhihao Yuan lichray

View GitHub Profile
@lichray
lichray / binary_literal.cc
Created November 27, 2012 12:23
User-defined binary literal in C++11
#include <iostream>
// http://stackoverflow.com/questions/537303/binary-literals
template<char... digits>
struct conv2bin;
template <char... digits>
constexpr int operator"" _b() {
return conv2bin<digits...>::value;
}
@lichray
lichray / kindle.tcsh
Created October 18, 2012 02:55
A tcsh alias to control Kindle on FreeBSD
# usage: kindle eject|start
# The 'start' command works for Kindle, but I saw an error message.
# However, I'm not silencing it here.
alias kindle 'camcontrol devlist | grep Kindle |'\
'sed -nE '\''s/^.*(pass[[:digit:]]+).*$/\1/p'\'' |'\
'xargs -J% camcontrol \!:1 % -E'
# Any brief command of camcontrol(8) is supported actually; 'eject'
# and 'start' are enough.
complete kindle 'p/1/(eject start)/'
@lichray
lichray / patch-mylogo
Created September 26, 2012 11:05
Customize xscreensaver's unlock dialog image.
@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__)
#!/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 / echo_test.c
Created July 12, 2012 19:06
A kqueue(2) example, read from stdin and echo.
/* Copyright (C) 2002 by Jilles Tjoelker */
/* revised by Zhihao Yuan, 2012 */
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <err.h>
#include <fcntl.h>
#include <signal.h>
@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/'`
+
@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 / 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 / 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];