View func_defaylt_values.py
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Author: Ficapy | |
# Create: '15/7/31' | |
# https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects | |
import requests | |
import time |
View check_status.py
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Author: Ficapy | |
# Create: '15/8/6' | |
import time | |
import math | |
import requests | |
from concurrent.futures import ThreadPoolExecutor, as_completed | |
from xlrd import open_workbook |
View regex_whole_file.py
import codecs | |
import re | |
import mmap | |
with codecs.open('a.txt', 'r+', 'utf-8') as f: | |
data = mmap.mmap(f.fileno(), 0) | |
print(re.findall(b'AccountType\=(.*)', data)) |
View adding_method.py
class A(object): | |
pass | |
a = A() | |
# 给类添加方法 | |
def baz(self): | |
print('baz') | |
A.baz = baz | |
# ==========或者 |
View json_output_chinese.py
# http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence | |
print(json.dumps({u'卧槽': u'卧槽'}, indent=4).decode('unicode-escape').encode('utf8')) | |
print(json.dumps({u'卧槽': u'卧槽'}, indent=4, ensure_ascii=False)) |
View chardetect.py
total = 2292627 | |
import sys | |
import codecs | |
from encodings.aliases import aliases | |
import mmap | |
all_encoding = aliases.values() | |
all_encoding = list(set(all_encoding)) |
View test.py
import random | |
from tt import retrys | |
def g(): | |
pass | |
class A(): | |
def __init__(self): |
View traverse_id.py
from concurrent.futures import ThreadPoolExecutor, as_completed | |
from user_agent import generate_user_agent | |
import requests | |
from pyquery import PyQuery as pq | |
def singal_parse(id): | |
url = 'http://www.miaoss.net/reg.php?id={}'.format(id) | |
ret = requests.get(url, params={'User-Agent': generate_user_agent()}, timeout=30) | |
ret.encoding = 'utf-8' |
View ubuntu_install_lxml
# ubuntu install lxml requires | |
sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev | |
# 在digitalocean 512M内存机器上报错,升级到1G内存正常 |
View random_file.txt
OSX: | |
http://osxdaily.com/2013/05/31/create-large-file-mac-os-x/ | |
mkfile -n size[b|k|m|g] filename | |
Others: | |
http://www.skorks.com/2010/03/how-to-quickly-generate-a-large-file-on-the-command-line-with-linux/ | |
dd if=/dev/zero of=somefile bs=1 seek=1G count=0 |