Skip to content

Instantly share code, notes, and snippets.

View TheWaWaR's full-sized avatar
🌀
Focusing

LingFeng TheWaWaR

🌀
Focusing
View GitHub Profile
@TheWaWaR
TheWaWaR / reloadlib.py
Last active March 10, 2024 01:32
Python reload shared library test script
#!/usr/bin/env python
#coding: utf-8
import os
import sys
import ctypes
def is_loaded(lib):
libp = os.path.abspath(lib)
ret = os.system("lsof -p %d | grep %s > /dev/null" % (os.getpid(), libp))
@TheWaWaR
TheWaWaR / mysql_dump.py
Last active August 29, 2015 14:18
Mysql dump python script (为了省内存,分片将 MySQL 表导出为 CSV 格式。)
#!/usr/bin/env python
#coding: utf-8
u"""
为了省内存,分片将 MySQL 表导出为 CSV 格式。
"""
import os
import argparse
from datetime import datetime
@TheWaWaR
TheWaWaR / init.el
Last active August 29, 2015 14:18
Simple emacs config file
;;;;;;;;;;;;;;; Install Emacs24.4 ;;;;;;;;;;;;;;
;; wget http://ftp.gnu.org/gnu/emacs/emacs-24.4.tar.xz
;; tar Jxf emacs-24.4.tar.xz
;; cd emacs-24.4
;; ./configure --with-x=no --with-x-toolkit=no --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no
;; make
;; sudo make install
(ido-mode)
(winner-mode)
@TheWaWaR
TheWaWaR / install-pkgs.sh
Last active August 29, 2015 14:18
Install packages
######## Based on Debian 7 ########
#### Node.js
# > https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
sudo apt-get install curl
sudo curl -sL https://deb.nodesource.com/setup | bash -
sudo apt-get install -y nodejs
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config get registry
import time
import math
# Retry decorator with exponential backoff
def retry(tries, delay=3, backoff=2):
'''Retries a function or method until it returns True.
delay sets the initial delay in seconds, and backoff sets the factor by which
the delay should lengthen after each failure. backoff must be greater than 1,
or else it isn't really a backoff. tries must be at least 0, and delay
@TheWaWaR
TheWaWaR / sqlalchemy2alembic.py
Last active August 29, 2015 14:13
SQLAlchemy definition to Alembic definition.
import re
VAR_REGEXP = "[_A-Za-z][_a-zA-Z0-9]*$"
COLUMN_MARK = 'db.Column('
DB_PREFIX = 'db.'
SA_PREFIX = 'sa.'
ALEMBIC_OP_NAME = 'op'
SQLALCHEMY_NAME = 'sa'
INDENT_1 = ' ' # 4 spaces
@TheWaWaR
TheWaWaR / slack.py
Last active April 21, 2016 03:02
Slack python webhook client
#coding: utf-8
import json
import requests
class Slack(object):
"""
References:
@TheWaWaR
TheWaWaR / db_fast_load.py
Last active August 29, 2015 14:08
Fast load sql to db (By disable autocommit)
#!/usr/bin/env python
#coding: utf-8
import pymysql as mdb
def read_statement(fd):
lines = []
while True:
line = fd.readline()
if not line:
#coding: utf-8
import os
import sys
import json
import commands
import ConfigParser
def supervisor(CONFIG_PATH):
@TheWaWaR
TheWaWaR / cap_win.py
Created October 14, 2014 23:47
Capture window by {xwd}
#!/usr/bin/env python
import os
import sys
def main(wid):
arg_dict = {'wid': wid}
CMD_XWD = 'xwd -id %(wid)d -out %(wid)d.xwd' % arg_dict