This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://blog.tonyseek.com/post/kill-the-descendants-of-subprocess/ | |
import signal | |
import os | |
import contextlib | |
import subprocess | |
import logging | |
import warnings | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
from time import sleep as _sleep | |
import db | |
# always sleep at least N seconds between retrys | |
_deadlock_MinSleepTime = 1.0/64 | |
# never sleep more than N seconds between retrys | |
_deadlock_MaxSleepTime = 3.14159 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[loggers] | |
keys = root, ..., sqlalchemy, sqlalchemy_pool | |
[logger_sqlalchemy_pool] | |
level = DEBUG | |
handlers = | |
qualname = sqlalchemy.pool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.orm import relationship | |
from sqlalchemy import Column, ForeignKey | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.dialects.mysql import INTEGER, CHAR | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'user' | |
__table_args__ = {'mysql_engine': 'InnoDB', 'sqlite_autoincrement': True, 'mysql_charset': 'utf8'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
printf "\033c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
import urllib | |
import sys | |
import re | |
def pager(city, fmt='utf-8'): | |
url = 'http://www.chapm25.com/city/{0}.html'.format(city) | |
page = urllib.urlopen(url).read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
from PIL import Image | |
import sys | |
def color2alpha(img, *color): | |
image = Image.open(img).convert("RGBA") | |
datas = image.getdata() | |
newData = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import sys | |
def cleanupString(string): | |
string = urllib2.unquote(string).decode('utf8') | |
return HTMLParser.HTMLParser().unescape(string).encode(sys.getfilesystemencoding()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define N 1000000 //the max value | |
#define MASK 0x1F | |
int a[1+N/32]; //int has 32 bits | |
void set(int i) { | |
a[i>>5] |= (1 << (i & MASK)); | |
} | |
void clear(int i) { | |
a[i>>5] &= ~(1 << (i & MASK)); |