Skip to content

Instantly share code, notes, and snippets.

View FingerLiu's full-sized avatar
😀
coding

FingerLiu FingerLiu

😀
coding
View GitHub Profile
@FingerLiu
FingerLiu / run_benchmark.py
Created June 4, 2017 04:19
benchmark_in_python
# copied from https://github.com/django-guardian/django-guardian/blob/devel/benchmarks/run_benchmarks.py
#!/usr/bin/env python
"""
This benchmark package should be treated as work-in-progress, not a production
ready benchmarking solution for django-guardian.
"""
import datetime
import os
import random
@FingerLiu
FingerLiu / im_in_terminal
Created June 4, 2017 04:17
curses 实现命令行聊天界面
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses, traceback, string
#-- Define the appearance of some interface elements
hotkey_attr = curses.A_BOLD | curses.A_UNDERLINE
menu_attr = curses.A_NORMAL
#-- Define additional constants
@FingerLiu
FingerLiu / get_open_port.py
Created June 4, 2017 04:15
获取一个未使用的端口
def get_open_port():
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("",0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port
@FingerLiu
FingerLiu / install_sqlite_3.14.sh
Created September 14, 2016 08:53 — forked from ziafazal/install_sqlite_3.14.sh
install custom sqlite(3.14) with pysqlite
# install custom sqlite 3.14
wget https://github.com/ghaering/pysqlite/archive/2.8.3.tar.gz
wget https://www.sqlite.org/2016/sqlite-autoconf-3140100.tar.gz
tar -xzvf sqlite-autoconf-3140100.tar.gz
tar -xzvf 2.8.3.tar.gz
cp -av sqlite-autoconf-3140100/. pysqlite-2.8.3/
cd ./pysqlite-2.8.3 && python setup.py build_static install
@FingerLiu
FingerLiu / decorator-example
Created January 23, 2015 05:04
use decorator to make a function elementwise.
def elementwise(fn):
def newfn(arg):
if hasattr(arg,'__getitem__'): # is a Sequence
return type(arg)(map(fn, arg))
else:
return fn(arg)
return newfn
@elementwise
def compute(x):