Skip to content

Instantly share code, notes, and snippets.

View limboinf's full-sized avatar
🎯
Focusing

limbo limboinf

🎯
Focusing
View GitHub Profile
@limboinf
limboinf / Bisection.py
Created July 1, 2016 09:47
bisect 二分查找源码分析
# coding=utf-8
"""
bisect实现源码就是**二分查找算法**,**二分查找的对象是:有序数组。这点特别需要注意。要先把数组排好序再操作。**
**基本步骤:**
- 从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;
- 如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。
- 如果在某一步骤数组为空,则代表找不到。
@limboinf
limboinf / sorted_list_operator.py
Created July 1, 2016 09:23
python bisect模块构造 有序list操作
# coding=utf-8
"""
python bisect模块构造 有序list操作
:copyright: (c) 2016 by fangpeng(@beginman.cn).
:license: MIT, see LICENSE for more details.
"""
import bisect
@limboinf
limboinf / find-cmd-exists.py
Created July 1, 2016 08:12
在pyprof2calltree这个项目中学到的在系统中查看命令是否存在
# 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
@limboinf
limboinf / api_sign_token.py
Created June 29, 2016 15:24
api请求和验证。
# coding=utf-8
"""
Api请求验证
:copyright: (c) 2016 by fangpeng(@beginman.cn).
:license: MIT, see LICENSE for more details.
"""
import uuid
import base64
import struct
@limboinf
limboinf / decorator-wraper-inspect.py
Created June 28, 2016 13:16
装饰器会用一个动态创建的新函数替换原来的。然而新函数缺少很多原函数的属性,如__doc__, __name__等,需要 from functools import wraps 复制这些属性给装饰器。 inspect模块运行提取函数的签名,如参数。
# coding=utf-8
"""
装饰器会用一个动态创建的新函数替换原来的。
然而新函数缺少很多原函数的属性,如__doc__, __name__等,
需要 from functools import wraps 复制这些属性给装饰器。
inspect模块运行提取函数的签名,如参数。
:copyright: (c) 2016 by fangpeng(@beginman.cn).
:license: MIT, see LICENSE for more details.
# 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
@limboinf
limboinf / 00-hello-web.py
Created June 17, 2016 03:02
Base webServer.
# coding=utf-8
"""
desc..
:copyright: (c) 2015 by fangpeng.
:license: MIT, see LICENSE for more details.
"""
__date__ = '16/6/17'
import BaseHTTPServer
@limboinf
limboinf / simple_http_v2.2.py
Created May 31, 2016 10:29
Python implements a http server by epoll(version 2.2, epoll, level-triggered, TCP_CORK)
# 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
@limboinf
limboinf / simple_http_v2.1.py
Created May 31, 2016 10:16
Python implements a http server by epoll(version 2.1, epoll, edge-triggered)
# 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'
@limboinf
limboinf / simple_http_v2.py
Last active May 31, 2016 10:01
Python implements a http server by epoll(version 2.0, epoll, level-triggered)
# 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'