Skip to content

Instantly share code, notes, and snippets.

@cxyfreedom
cxyfreedom / delay_queue.py
Created March 26, 2020 07:46
使用 zset 来实现延迟队列
# -*- coding: utf-8 -*-
"""
@author: cxyfreedom
@desc: 使用 zset 来实现延迟队列
"""
import redis
import time
import threading
@cxyfreedom
cxyfreedom / bvtest.py
Created March 24, 2020 02:49 — forked from abc1763613206/bvtest.py
BVID Validate
import requests
import json
import random
Back_URL = 'https://api.bilibili.com/x/web-interface/archive/stat?aid='
headers = {
'Cookie': "Replace Me With REAL COOKIE" ,
'Pragma': 'no-cache',
@cxyfreedom
cxyfreedom / snowflake.py
Created January 7, 2020 03:27
使用 Python 来模拟实现 snowflake 算法
# -*- coding: utf-8 -*-
"""
@author: cxyfreedom
@desc: 基于 snowflake 生成分布式ID
"""
import time
# 每一部分占用的位数
TIMESTAMP_BIT = 41 # 时间戳占用位数
MACHINE_BIT = 5 # 机器标识占用的位数
@cxyfreedom
cxyfreedom / asyncio_http.py
Last active January 6, 2020 13:45
use asyncio package to implement http request
# -*- coding: utf-8 -*-
import asyncio
from urllib.parse import urlparse
async def get(url):
url = urlparse(url)
host = url.netloc
path = url.path or "/"
# -*- coding: UTF-8 -*-
import hashlib
import hmac
import string
import datetime
import time
import uuid
import json
import requests