Skip to content

Instantly share code, notes, and snippets.

View TheWaWaR's full-sized avatar
🌀
Focusing

LingFeng TheWaWaR

🌀
Focusing
View GitHub Profile
@TheWaWaR
TheWaWaR / .gitignore
Created July 5, 2014 06:44
Base .gitignore
\#*
*~
*.swp
*.py[oc]
*.bin
flymake_*
@TheWaWaR
TheWaWaR / log_rotate.py
Created June 17, 2014 01:30
Log Rotate
import glob
import logging
import logging.handlers
LOG_FILENAME = 'logging_rotatingfile_example.out'
# Set up a specific logger with our desired output level
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
@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
@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 / 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
#!/usr/bin/env python
#coding: utf-8
# ==============================================================================
# python -m doctest -v test_rsub.py
# ==============================================================================
class Left1(int):
"""
@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
@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 / 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 / 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):