Skip to content

Instantly share code, notes, and snippets.

from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run(host='localhost', port=8080, debug=True)
@baojie
baojie / bookpaste.py
Last active January 3, 2016 03:39
monitor clipboard and save contents to a file
# sudo apt-get install xclip
# sudo pip install xerox begin
import time
import sys
import os
import io
import xerox
import begin
@baojie
baojie / flask-vs-tornado
Created December 3, 2013 23:42
flask vs tornado benchmark on basic routing and template rendering
Flask, Python 2.7, Single core 271.97 [#/sec] (mean)
Flask, Pypy, Single core 547.11
Flask+Gunicorn, Python, 8Core 1363.06
Flask+Gunicorn, Pypy, 8Core 2701.90
Flask+Gunicorn+Tornado, Python, 8Core 1403.88
Flask+Gunicorn+Tornado, Pypy, 8Core 2582.12
Tornado, Python, Single core 839.65
Tornado, Async, Python, Single core 801.19
Tornado, Pypy, Single core 1841.41
Tornado, Async, Pypy, Single core 1734.37
# -*- coding: utf-8 -*-
"""
To install pylinkgrammar on Ubuntu
sudo apt-get install liblink-grammar4-dev cmake swig
pip install pylinkgrammar
"""
from pylinkgrammar.linkgrammar import Parser
# -*- coding: utf-8 -*-
"""
Test MBSP parsing
Help on clips.MBSP
http://www.clips.ua.ac.be/pages/MBSP
"""
import MBSP
from time import time
@baojie
baojie / git_alias.sh
Last active December 23, 2015 02:39
install some useful git shortcuts. Depends on https://github.com/visionmedia/git-extras
# show log in online and color
# Usage: tig
sudo apt-get install tig
# git extras
# Usage: see https://github.com/visionmedia/git-extras
(cd /tmp && git clone --depth 1 https://github.com/visionmedia/git-extras.git && cd git-extras && sudo make install)
# full commit history with diff of a file
# Usage: git history foo.py
#!/bin/sh
echo "data:image/png;base64,`base64 $1`"
$ cat /proc/cpuinfo | grep "model name" | uniq
model name : Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz
$ uname -a
Linux Q8400 3.5.0-37-generic #58-Ubuntu SMP Mon Jul 8 22:07:55 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 2.7.3
$ python -m timeit '"-".join(str(n) for n in range(100))'
10000 loops, best of 3: 24.4 usec per loop
#!/usr/bin/python
import time
# sudo apt-get install python-daemon
from daemon import runner
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
@baojie
baojie / hello_blob.py
Created August 27, 2013 21:43
https://pypi.python.org/pypi/textblob Simple, Pythonic text processing. Sentiment analysis, POS tagging, noun phrase parsing, and more.
from text.blob import TextBlob
text = '''
The titular threat of The Blob has always struck me as the ultimate movie
monster: an insatiably hungry, amoeba-like mass able to penetrate
virtually any safeguard, capable of--as a doomed doctor chillingly
describes it--"assimilating flesh on contact.
Snide comparisons to gelatin be damned, it's a concept with the most
devastating of potential consequences, not unlike the grey goo scenario
proposed by technological theorists fearful of