Skip to content

Instantly share code, notes, and snippets.

@myvyang
myvyang / thread_pool.py
Last active August 21, 2018 06:47
简易线程池
# -*- coding: utf-8 -*-
#author: myvyang#gmail.com
import threading
import Queue
__all__ = ["ThreadPool"]
class ThreadPool(object):
// Javascript 函数与对象 起源
// 先来看看几个东西
// typeof 作用符: 查看类型
typeof 1
typeof x
@myvyang
myvyang / absolute.js
Created September 7, 2017 06:21
absolute url
function absolute(location, relative) {
if (relative.startsWith("http://")
|| relative.startsWith("https://")
|| relative.startsWith("data:")) {
return relative;
}
if (relative.startsWith("//")) {
return location.protocol + relative;
}
function request(url, method, data, callback) {
function ready() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
callback(httpRequest.responseText);
}
}
}
# -*- utf-8 -*-
from __future__ import division
NUMBER_TAG = "{NUM}"
class Node(object):
def __init__(self, name):
self.parent = None
self.children = set()
import requests
import re
url = "https://weibo.com/p/aj/album/loading?ajwvr=6&type=photo&owner_uid=1935400180&viewer_uid=1935400180&since_id=4266739550726685_-1_20180831_-1&page_id=1005051935400180&page=2&ajax_call=1&__rnd=1539765676886"
re_img = "curclear_picSrc=(.*?)%3F"
re_since = "since_id=([0-9_-]+)"
while True:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Python3 only """
import requests
import http
http.client.HTTPConnection._http_vsn = 10
http.client.HTTPConnection._http_vsn_str = "HTTP/1.0"
1. 所有操作设置超时;保证限定时间内完成,或报错;
2. 错误隔离;保证错误在一个小范围内,不会影响整个程序的运行,失败的任务记录下来;
REQ: GET /api/v1/object/{number}/property
REQ: POST /api/v1/object/{number}/action
{"xx": "xx"}
RES: {
"code": 0/1/-1,
"msg": "",
"resp": {
}
def json_structure(j):
"""
JSON有三种结构:字面值(int, bool, str), dict, list
为简化处理,将list通过转换视为dict结构,key为序号。
["a", 1] -> {"0": "a", "1": 1}
这个函数返回json的结构信息,"值"会被丢弃。
{"a": 1, "b": ["n", false]}
->