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 multipliers(): | |
return [lambda x : i * x for i in range(4)] | |
print [m(2) for m in multipliers()] | |
def multipliers(): | |
for i in range(4): yield lambda x : i * x | |
def multipliers(): |
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
group by 搭配聚合函数来用 |
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
from PIL import Image | |
import argparse | |
ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-A_MTYUEJD+~<>i!lI;:,\"^`'. ") | |
def get_char(r, g, b, alpha=256): | |
if alpha == 0: | |
return ' ' | |
length = len(ascii_char) |
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
from select import select | |
import socket | |
import Queue | |
server = socket.socket() | |
server.bind(('127.0.0.1', 8888)) | |
server.listen(5) | |
server.setblocking(0) | |
input_list = [server, ] |
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 socket | |
import select, errno | |
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
serversocket.bind(('0.0.0.0', 8888)) | |
serversocket.listen(1) | |
serversocket.setblocking(0) | |
epoll_fd = select.epoll() |
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
@manager.command | |
def list_routes(): | |
import urllib | |
output = [] | |
for rule in app.url_map.iter_rules(): | |
if rule.endpoint == 'static': | |
continue | |
methods = ','.join(rule.methods) | |
line = urllib.unquote("{:30s} {:30s} {}".format(rule.rule, rule.endpoint, methods)) | |
output.append(line) |
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
关键:timestamp是不带时区的,但是拿timestamp转datetime的时候你的datetime是带时区的 | |
或者说拿着这个timestamp是没有用的,因为需要根据不同的时区才能转化成对应时区的时间 | |
datetime = timestamp(时间戳) + tzinfo(地区) | |
1 · 换成带时区的datetime计算 | |
epoch = datetime(1970, 1, 1) | |
def datetime_to_timestamp(dt): | |
dt = dt - dt.tzinfo.utcoffset(dt) | |
td = dt - epoch.replace(tzinfo=dt.tzinfo) |
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
1·共享锁,排它锁。 | |
共享锁【S锁】 | |
又称读锁,若事务T对数据对象A加上S锁,则事务T可以读A但不能修改A,其他事务只能再对A加S锁,而不能加X锁,直到T释放A上的S锁。这保证了其他事务可以读A,但在T释放A上的S锁之前不能对A做任何修改。 | |
排他锁【X锁】 | |
又称写锁。若事务T对数据对象A加上X锁,事务T可以读A也可以修改A,其他事务不能再对A加任何锁,直到T释放A上的锁。这保证了其他事务在T释放A上的锁之前不能再读取和修改A。 | |
-查询是否锁表了 | |
select oid from pg_class where relname='可能锁表了的表' |
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
1.hash 通过函数h将输入映射到一个固定的位置,h(i) = position,最简单的hash函数就是 h(i) = i mod Table_Size | |
2.Table_Size最好就是一个素数 | |
3.hash就一定会有碰撞,常用的方法open address法,即当发生碰撞的时候,如何寻找下一个空位(装填因子应该小于0.5)。 | |
1.线性探测。F(i)=i,发生碰撞之后,探测发生碰撞位置的下一个是否为空。缺点,形成区块聚堆 | |
2.平方探测法。F(i)=i^2,发生碰撞之后,按照1,4,9,16这样的距离寻找空位 | |
3.使用open address法,当装填太多的时候,效率会降低。这个时候需要rehash,将table扩容,对原来的数据全部再hash一次。 | |
4.常用hash函数(http://blog.csdn.net/jason5186/article/details/9037623) | |
hash table主要函数 | |
1.insert |
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=utf8 -*- | |
import time | |
now = time.time() | |
word = '....' | |
i = 0 | |
ar = ['-', '\\', '|', '/'] | |
import sys |
OlderNewer