Skip to content

Instantly share code, notes, and snippets.


Mocker Zuckonit

  • Hangzhou China
View GitHub Profile
import signal
import os
import contextlib
import subprocess
import logging
import warnings
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
keys = root, ..., sqlalchemy, 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 /
Created Feb 26, 2014
truly clear the screen in terminator
#!/usr/bin/env bash
printf "\033c"
Zuckonit /
Created Feb 26, 2014
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 = '{0}.html'.format(city)
page = urllib.urlopen(url).read()
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 ="RGBA")
datas = image.getdata()
newData = []
Zuckonit /
Created Feb 17, 2014
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())
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.