Skip to content

Instantly share code, notes, and snippets.

View liuyix's full-sized avatar

Yi Liu liuyix

View GitHub Profile
@liuyix
liuyix / py-stack-mid-expression.py
Created August 30, 2013 15:42
python stack 实现 + 中缀表达式计算
import logging
class Stack:
def __init__(self):
self.__space = []
self.cur = -1
def pop(self):
if self.cur == -1:
logging.warn("pop an empty stack")
return None
class QueueItem:
def __init__(self, data):
self.data = data
self.next = None
def __repr__(self):
string = "Data: {}".format(str(self.data))
return string
class LinkedQueue:
def __init__(self):
@liuyix
liuyix / bash-read-line-by-line.sh
Created August 28, 2013 02:27
bash script: read line by line
#Credit: http://stackoverflow.com/a/4642213/668223
FILE=test
while read CMD; do
echo "$CMD"
done < "$FILE"
@liuyix
liuyix / command.sh
Created August 27, 2013 03:01
android screenshot by adb command
adb shell screencap -p | sed 's/\r$//' > screen.png
def start_thread_wrapper(target_func,name='thread-', thread_number=1,daemon=True, args=()):
assert target_func != None and hasattr(target_func, '__call__')
for i in xrange(thread_number):
t = threading.Thread(target=target_func,name=name+str(i), args=args)
t.daemon = daemon
t.start()
@liuyix
liuyix / python-call-external-program.py
Last active December 21, 2015 08:18
python 调用外部程序,拿到返回值
# http://stackoverflow.com/a/707001/668223
import os
from subprocess import Popen, PIPE
process = Popen(["ls", "-la", "."], stdout=PIPE)
exit_code = os.waitpid(process.pid, 0)
output = process.communicate()[0]
# 更好的做法应该是
# http://docs.python.org/2/library/subprocess.html
@liuyix
liuyix / gist:6217694
Created August 13, 2013 03:37
PF_UNIX, AF_UNIX, PF_LOCAL, AF_LOCAL
http://blog.csdn.net/qiaoliang328/article/details/4722377
http://alas.matf.bg.ac.rs/manuals/lspe/snode=38.html
@liuyix
liuyix / yank_select.md
Created August 13, 2013 03:21
emacs Cut, Copy, and Paste

copy/cut多个文本,可以通过 C-y 粘贴,之后通过多次 M-y 逐个选择

#define LOGE(fmt,args...) fprintf(stderr, fmt, ##args)
#define LOGD(fmt,args...) fprintf(stderr, fmt, ##args)
#define LOGW(fmt,args...) fprintf(stderr, fmt, ##args)
#include <errno.h>
#include <string.h>
#define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
#define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
@liuyix
liuyix / python-distribution.md
Created August 5, 2013 05:41
Python program distribution