Skip to content

Instantly share code, notes, and snippets.

View TheWaWaR's full-sized avatar
🌀
Focusing

LingFeng TheWaWaR

🌀
Focusing
View GitHub Profile
@TheWaWaR
TheWaWaR / Install-rtorrent.sh
Last active December 30, 2015 16:09
Install Linux Command Line BitTorrent client in CentOS 6.4.
# 1. Install the dependencies
yum install gcc-c++ libsigc++20-devel
# 2. Install libTorrent
wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.3.tar.gz
./configure --prefix=$HOME/local && make && make install
# 3. Install the client
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.3.tar.gz
export PKG_CONFIG_PATH=$HOME/local/lib/pkgconfig
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template
app = Flask(__name__)
app.debug = True
@app.route('/')
def index():
return render_template('index.html')
@TheWaWaR
TheWaWaR / test_yield.py
Last active January 1, 2016 16:29
Test Python yield
#coding: utf-8
from datetime import datetime
import time
# ==============================================================================
# Test yield
# ==============================================================================
def test_yield():
for i in range(4):
@TheWaWaR
TheWaWaR / memoize_decorator.py
Created January 27, 2014 09:11
Memoize decorator function with cache size limit (Python recipe)
import cPickle
__all__ = ["memoize"]
def memoize(function, limit=None):
if isinstance(function, int):
def memoize_wrapper(f):
return memoize(f, function)
return memoize_wrapper
@TheWaWaR
TheWaWaR / gunicorn_config.py
Last active June 28, 2022 11:31
Gunicorn configuration sample
import os
app = '{YOUR-WSGI-APPLICATION}'
# Sample Gunicorn configuration file.
#
# Server socket
#
# bind - The socket to bind.
@TheWaWaR
TheWaWaR / gunicorn_service.py
Last active October 5, 2023 12:54
Gunicorn service script {Start | Restart | Stop | Reload | Quit}
#!/usr/bin/env python
#coding: utf-8
import os
import imp
import time
import signal
import argparse
import commands
#!/usr/bin/env python
#coding: utf-8
# ==============================================================================
# python -m doctest -v test_rsub.py
# ==============================================================================
class Left1(int):
"""
@TheWaWaR
TheWaWaR / build-debian7-x64-env.sh
Last active October 13, 2015 14:04
Build a Debian 7 (x64) Environment
############################################################
# 1. Install debian 7 by live CD
############################################################
# grub> ls /
# grub> linux /vmlinuz
# grub> initrd /initrd.gz
# grub> boot
@TheWaWaR
TheWaWaR / double-fork-daemon.py
Created June 6, 2014 06:59
UNIX double-fork magic to let process be daemon
def spawnDaemon(func):
# do the UNIX double-fork magic, see Stevens' "Advanced
# Programming in the UNIX Environment" for details (ISBN 0201563177)
try:
pid = os.fork()
if pid > 0:
# parent process, return and keep running
return
except OSError, e:
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
@TheWaWaR
TheWaWaR / command-func-timeout.py
Last active August 29, 2015 14:02
subprocess.Popen execute Command / Invoke function timeout control.
#coding: utf-8
import os
import time
import signal
# from datetime import datetime
from multiprocessing import Process, Queue
import subprocess
import threading