Skip to content

Instantly share code, notes, and snippets.

View lttzzlll's full-sized avatar

liutaotao lttzzlll

  • http://metasota.ai/
View GitHub Profile
import concurrent.futures
import urllib.request
import requests
import os
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"}
URLS = ['http://www.jianshu.com/',
@lttzzlll
lttzzlll / heap_sort_demo.py
Created April 30, 2018 08:48
heap sort demo
import unittest
def sift_down(lst, top, end):
pos = end
newitem = lst[pos]
while pos > top:
parentpos = (pos - 1) >> 1
parent = lst[parentpos]
if newitem < parent:
from collections import namedtuple
Result = namedtuple('Result', 'Count Averge')
def averger():
count = 0
total = 0
avg = None
while True:
term = yield avg
import hashlib
from concurrent import futures
import os
import time
from itertools import chain
from functools import wraps
def timeit(func):
@wraps(func)
@lttzzlll
lttzzlll / md5_file.py
Created April 27, 2018 06:04
python md5 two files
import hashlib
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()
import concurrent.futures
import urllib.request
import requests
import os
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"}
URLS = ['http://www.jianshu.com/',
@lttzzlll
lttzzlll / python_interview3.md
Last active May 15, 2018 10:43
some interview questions about python backend

1、什么是协程?--> yield 有什么作用?--> yield 实现协程底层是怎么实现的?--> yield from 又是什么?

协程,又称微线程,纤程。英文名Coroutine。

协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用。

子程序,或者称为函数,在所有语言中都是层级调用,比如A调用B,B在执行过程中又调用了C,C执行完毕返回,B执行完毕返回,最后是A执行完毕。

所以子程序调用是通过栈实现的,一个线程就是执行一个子程序。

@lttzzlll
lttzzlll / check.py
Created April 24, 2018 07:35
using multiprocessing to check file exists or not
import subprocess
import asyncio
from itertools import chain
from functools import wraps
import concurrent
import time
import readxml
EXE = r"\\ccpsofsep\am_s1\users\v-taotli\code\CollectData\CollectData\CollectData\bin\Debug\CollectData.exe"
@lttzzlll
lttzzlll / heap_sort.py
Created April 19, 2018 09:30
heap sort using heapq
import random
def heap_sort(ints):
heapify(ints)
res = []
while ints:
res.append(heappop(ints))
return res
import random
def merge_sort(ints):
length = len(ints)
if length < 2:
return ints
mid = length >> 1
left, right = merge_sort(ints[:mid]), merge_sort(ints[mid:])
left_count, right_count = len(left), len(right)