Skip to content

Instantly share code, notes, and snippets.

View Zuckonit's full-sized avatar
:octocat:
I may be slow to respond.

Mocker Zuckonit

:octocat:
I may be slow to respond.
View GitHub Profile
@Zuckonit
Zuckonit / killer.py
Last active August 29, 2015 14:14
killer.py
#https://blog.tonyseek.com/post/kill-the-descendants-of-subprocess/
import signal
import os
import contextlib
import subprocess
import logging
import warnings
@Zuckonit
Zuckonit / deadlock.py
Created September 4, 2014 17:15
deadlock.py
#
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
[loggers]
keys = root, ..., sqlalchemy, sqlalchemy_pool
[logger_sqlalchemy_pool]
level = DEBUG
handlers =
qualname = sqlalchemy.pool
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'}
@Zuckonit
Zuckonit / clear.sh
Created February 26, 2014 08:29
truly clear the screen in terminator
#!/usr/bin/env bash
printf "\033c"
@Zuckonit
Zuckonit / pm25.py
Created February 26, 2014 07:18
get the pm2.5 of special city
#!/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()
@Zuckonit
Zuckonit / white2alpha
Created February 17, 2014 03:18
替换图片白色为透明
#!/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 = []
@Zuckonit
Zuckonit / unescape.py
Created February 17, 2014 03:12
unescape html to python string
import urllib2
import sys
def cleanupString(string):
string = urllib2.unquote(string).decode('utf8')
return HTMLParser.HTMLParser().unescape(string).encode(sys.getfilesystemencoding())
@Zuckonit
Zuckonit / bitmap.c
Created December 11, 2013 07:03
bitmap
#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));