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
''.join([ '{0:08b}'.format(ord(i)) for i in src ]) |
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
def md5(fname): | |
hash_md5 = hashlib.md5() | |
with open(fname, "rb") as f: | |
for chunk in iter(lambda: f.read(4096), b""): | |
hash_md5.update(chunk) | |
return hash_md5.hexdigest() |
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 inspect | |
def displayattrs(objects): | |
attrs = inspect.getmembers(objects) | |
for attr in attrs: | |
attr = attr[0] | |
filters = ['_', '__'] | |
if not any(map(attr.startswith, filters)): | |
doc = getattr(objects, attr).__doc__ | |
if doc: |
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 os | |
def randomString(n): | |
return (''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(n))))[0:16] | |
print randomString(16) | |
""" | |
os.urandom(n) : 随机生成n个字节的串,一个字节是8位,我猜是这8位二进制数是随机的,所以这个字节也是随机的。所以没有指定的编码方案可以很好地把所有这个字符串显示转换成功,即有可能会乱码 |
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 os | |
# Using Flask since Python doesn't have built-in session management | |
from flask import Flask, session, render_template | |
# Our target library | |
import requests | |
import json | |
app = Flask(__name__) | |
# Generate a secret random key for the session |
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 -*- | |
""" | |
by hx, 2015.11.24 | |
version:python2.7.x | |
""" | |
def factorial(x): | |
res = 1 |
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
# 日志打印屏幕或文件 | |
def setup_logger_2(logger_name, level=logging.INFO, handler='all', log_file=''): | |
""" | |
:param logger_name: | |
:param log_file: | |
:param level: | |
:param handler: file or stream or all | |
:return: | |
""" | |
log_setup = logging.getLogger(logger_name) |
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
# -*- coding: utf-8 -*- | |
# auto upgrade python package | |
# need root privilige | |
""" | |
import pip | |
from subprocess import call | |
for dist in pip.get_installed_distributions(): | |
call("pip install --upgrade " + dist.project_name, shell=True) |
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
def is_intersection(a, b): | |
''' | |
input: | |
a = [1, 2, 3] | |
b = [3, 6, 9] | |
output: | |
True | |
''' | |
return any(_ in a for _ in b) |
NewerOlder