Skip to content

Instantly share code, notes, and snippets.

Mocker Zuckonit

  • Hangzhou China
View GitHub Profile
View killer.py
#https://blog.tonyseek.com/post/kill-the-descendants-of-subprocess/
import signal
import os
import contextlib
import subprocess
import logging
import warnings
View 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
View enable_alchemy_pool_logging.ini
[loggers]
keys = root, ..., sqlalchemy, sqlalchemy_pool
[logger_sqlalchemy_pool]
level = DEBUG
handlers =
qualname = sqlalchemy.pool
View onetomany
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 Feb 26, 2014
truly clear the screen in terminator
View clear.sh
#!/usr/bin/env bash
printf "\033c"
@Zuckonit
Zuckonit / pm25.py
Created Feb 26, 2014
get the pm2.5 of special city
View pm25.py
#!/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 Feb 17, 2014
替换图片白色为透明
View white2alpha
#!/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 Feb 17, 2014
unescape html to python string
View unescape.py
import urllib2
import sys
def cleanupString(string):
string = urllib2.unquote(string).decode('utf8')
return HTMLParser.HTMLParser().unescape(string).encode(sys.getfilesystemencoding())
View bitmap.c
#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));
You can’t perform that action at this time.