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 | |
""" | |
bisect实现源码就是**二分查找算法**,**二分查找的对象是:有序数组。这点特别需要注意。要先把数组排好序再操作。** | |
**基本步骤:** | |
- 从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束; | |
- 如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。 | |
- 如果在某一步骤数组为空,则代表找不到。 |
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 | |
""" | |
python bisect模块构造 有序list操作 | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import bisect | |
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 | |
""" | |
在pyprof2calltree这个项目中学到的在系统中查看命令是否存在 | |
https://github.com/pwaller/pyprof2calltree/blob/master/pyprof2calltree.py | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import os | |
import sys |
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 | |
""" | |
Api请求验证 | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import uuid | |
import base64 | |
import struct |
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 | |
""" | |
装饰器会用一个动态创建的新函数替换原来的。 | |
然而新函数缺少很多原函数的属性,如__doc__, __name__等, | |
需要 from functools import wraps 复制这些属性给装饰器。 | |
inspect模块运行提取函数的签名,如参数。 | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. |
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 | |
""" | |
This version responds to HTTP requests with static HTML files or | |
directory listings. | |
* Run with `python server.py .` (or some other base directory name). | |
* Point browser at `http://localhost:8080/some/path`. | |
Usage: | |
curl localhost:9000/demo.html |
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 | |
""" | |
desc.. | |
:copyright: (c) 2015 by fangpeng. | |
:license: MIT, see LICENSE for more details. | |
""" | |
__date__ = '16/6/17' | |
import BaseHTTPServer | |
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 | |
""" | |
TCP_CORK 参数可以设置缓存消息直到一起被发送 | |
这个选项, 在下例中的45和53行使用 | |
适合给一个实现 http/1.1pipelining 的服务器来使用. | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import socket |
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 | |
""" | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import socket | |
import select | |
EOL1 = b'\n\n' | |
EOL2 = b'\n\r\n' |
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 | |
""" | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import socket | |
import select # select模块带有epoll功能 | |
EOL1 = b'\n\n' | |
EOL2 = b'\n\r\n' |