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 | |
""" | |
在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 | |
""" | |
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 | |
""" | |
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之父教你写main()函数 | |
---------------------------------- | |
main()函数使其接受一个可选参数 argv,支持在交互式shell中调用该函数, | |
我们就可以动态地提供 argv 的值。 | |
让main()函数的返回值指示退出状态(exit status)并且, | |
main()函数中的sys.exit(n)调用全部变成return 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
package main | |
import ( | |
"fmt" | |
) | |
func fib(c, quit chan int) { | |
x, y := 0, 1 | |
// select 语句使得一个goroutine在多个通讯操作上等待 | |
// select 会阻塞,直到条件分支中的某个可以继续执行,如果有多个可执行,则随机执行一个 |
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 | |
""" | |
Two ways to check the request of the integrity of the fields | |
valid_req_field: Primitive way | |
valid_req_field_by_compress: itertools.compress() | |
""" | |
import itertools | |
def valid_req_field(req_data, *args): |
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 | |
""" | |
tornado异步爬虫示例 | |
""" | |
import time | |
from datetime import timedelta | |
from bs4 import BeautifulSoup | |
from tornado.httpclient import AsyncHTTPClient | |
from tornado import ioloop, gen, queues |
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 Cookbook》11.12 理解事件驱动型I/O | |
事件驱动I/O是一种将基本的I/O操作(即:读和写)转换成事件的技术,而我们必须在程序中去处理这种事件。 | |
比如当socket上都到数据时,这成为一个"接收事件", 由我们提供的回调方法或函数去负责处理以此响应这个事件。 | |
一个事件驱动框架可能会以一个基类作为起始点,实现一系列基本的事件处理方法。 | |
: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
#include <stdio.h> | |
#include <stdlib.h> | |
int comp(const void *, const void *); | |
int main() | |
{ | |
int *array; | |
int n_values; | |
int i; |