Skip to content

Instantly share code, notes, and snippets.

@mywaiting
mywaiting / asyncio_loop_in_thread.py
Created November 14, 2024 08:52 — forked from dmfigol/asyncio_loop_in_thread.py
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@mywaiting
mywaiting / insert_iframe.js
Created November 12, 2024 07:28
简单方便的插入的 iframe 的实现
function insert_iframe(srcdoc) {
// 首先清理所有的已经插入的 iframe
// https://stackoverflow.com/a/65413839
document.getElementById("web-browser").replaceChildren()
// 此处再考虑重新插入新的 iframe
const $el = document.createElement("iframe")
Object.assign($el, {
id: "iframe",
className: "iframe",
name: "iframe",
@mywaiting
mywaiting / install_pyspider.md
Last active November 9, 2024 16:07
安装 PySpider 无坑教程

安装 PySpider 无坑教程

特别不建议在 python 3 中安装 pyspider 包括 python 3.5/3.6/3.7 有很多其他的问题,比如说 async 关键字的问题

首先安装 Python 2.7 版本,由于是 老旧版本,截至到 2024/11 最新的是 2.7.18 版本,可以参考 SF 介绍博客 The final Python 2 release marks the end of an era,可以使用 Pyenv/Virtualenv 单独安装一个,我这里用 Python 2.7.6 版本作为演示使用

注意:此处限制并且强烈推荐只使用 Python 2.7 版本!!!

@mywaiting
mywaiting / token_bucket.py
Created June 3, 2024 02:09
基于时间计算的令牌桶实现 - 注意:令牌桶算法实现上另一个细节就是进程/线程锁,如果不使用后端组件比如 Redis 则实现上必须加入锁实现(此时后端组件相当于另一种形式上锁实现), 尽管单进程/线程执行代码的无所谓,但多进程/线程执行代码时,令牌桶的数据就会混乱,此处还是带锁执行比较稳妥 - 注意:令牌桶原始意思应该有个定时器,定期往桶里塞入固定数量的令牌除非溢出, 但多数代码实现上都是取令牌时计算上次消耗到本次消耗时间差中生成令牌数量,没有原始意义上塞令牌的代码
#!/usr/bin/env python
#
# 精简实现的令牌桶算法
# 注意:此处实现上都是取令牌时计算上次消耗到本次消耗时间差中生成令牌数量,没有原始意义上往桶塞令牌的实现
# 注意:此处实现上有简单的进程锁,防止多线程/进程读取数据产生混乱
#
import time
@mywaiting
mywaiting / python_gzip.py
Created March 5, 2024 03:30
Python GZIP 安全实现,抄袭自 Python 官方 xmlrpc.client 能通过限制解压大小限制 GZIP bomb 的实现
# THIS FORM python.stdlib xmlrpc.client
# this avoid gzip bomb vulnerability
try:
import gzip
except ImportError:
gzip = None #python can be built without zlib/gzip support
##
@mywaiting
mywaiting / 01.js
Created April 15, 2022 06:40 — forked from vielhuber/01.js
Google Translate API Hacking #knowhow #tools
function Bp(a, b) {
var c = b.split(".");
b = Number(c[0]) || 0;
for (var d = [], e = 0, f = 0; f < a.length; f++) {
var h = a.charCodeAt(f);
128 > h ? d[e++] = h : (2048 > h ? d[e++] = h >> 6 | 192 : (55296 == (h & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (h = 65536 + ((h & 1023) << 10) + (a.charCodeAt(++f) & 1023), d[e++] = h >> 18 | 240, d[e++] = h >> 12 & 63 | 128) : d[e++] = h >> 12 | 224, d[e++] = h >> 6 & 63 | 128), d[e++] = h & 63 | 128)
}
a = b;
for (e = 0; e < d.length; e++) a += d[e], a = Ap(a, "+-a^+6");
a = Ap(a, "+-3^+b+-f");
@mywaiting
mywaiting / __cpc.sw.js
Created September 11, 2019 16:06
https://www.croxyproxy.com/ 的 ServiceWorker 浏览器端的代理脚本,解密之后可以使用
​(new Function(atob('NzY2MTcyMjA1ZjMwNzgzMzM0NjQzMzNkNWIyNzVmNWY2MzcwNGY3MjY5Njc2OTZlNjE2YzQ0NjE3NDYxMjcyYzI3NWY1ZjZmNzI2OTY3Njk2ZTI3MmMyNzRkNjU3MzczNjE2NzY1NDU3NjY1NmU3NDI3MmMyNzY0NjE3NDYxMjcyYzI3NDU3ODc0NjU2ZTY0NjE2MjZjNjU0ZDY1NzM3MzYxNjc2NTQ1NzY2NTZlNzQyNzJjMjc2OTZlNjk3NDRjNmY2MzYxNzQ2OTZmNmUyNzJjMjc1NzZmNzI2YjY1NzI0YzZmNjM2MTc0Njk2ZjZlMjcyYzI3NGM2ZjYzNjE3NDY5NmY2ZTI3MmMyNzcwNjE3MzczNjk3NjY1NGQ2ZjY0NjUyNzJjMjc2ODYxNzM2ODYzNjg2MTZlNjc2NTI3MmMyNzYxNjQ2NDQ1NzY2NTZlNzQ0YzY5NzM3NDY1NmU2NTcyMjcyYzI3NzA2ZjcwNzM3NDYxNzQ2NTI3MmMyNzYxNzM3MzY5Njc2ZTI3MmMyNzcyNjU2YzZmNjE2NDI3MmMyNzYyNjE3MzY1MjcyYzI3NjI2MTczNjU1YjI3MmMyNzY5NmU2OTc0NTU3MjY5MjcyYzI3NzU3MjY5MjcyYzI3Njg3NDc0NzAyNzJjMjc2ODc0NzQ3MDczMjcyYzI3NjU3NjY1NzI3OTI3MmMyNzNmNzIzZDI3MmMyNzY1NzE3NTYxNmM3MzI3MmMyNzRlNmY1Yzc4MzIzMDZmNzI2OTY3Njk2ZTVjNzgzMjMwNjY2ZjcyNWM3ODMyMzA3NTcyNmM1Yzc4MzIzMDI3MmMyNzJjNWM3ODMyMzA3MDZmNzM3MzY5NjI2YzY1NWM3ODMyMzA3MjY1NzM3NTZjNzQ1Yzc4MzIzMDY5NzM1Yzc4MzIzMDI3MmMyNzNiNWM3ODMyMzA2MjYxNzM2NTVjNzgzMjMwNzU3MjZjM2E1Yzc4MzIzMDI3MmMyNzU3NzI2ZjZlNjc
@mywaiting
mywaiting / nginx.md
Created July 26, 2019 15:53
日常使用 Nginx 的一些常见的知识点,写下来权当备忘吧,毕竟好记性不如烂笔头

Nginx 知识指南

本文档包含了Nginx在Ubuntu下面的点点滴滴。包含了我常用的Nginx常用的配置文件。

安装Nginx

在Ubuntu终端里面敲入命令:

apt-get update

apt-get upgrade

@mywaiting
mywaiting / tasks.py
Created July 26, 2019 09:31
使用 python tornado 框架异步调用 celery 队列任务的实现,很简单的小函数,但是很好用
from celery import Celery
import time
celery = Celery('tasks', backend='redis://localhost', broker='amqp://')
@celery.task
def test(strs):
return strs
-- MySQL dump 10.13
--
-- Pinboard database schema
-- Feel free to use this however you like. Send questions to [email protected].
-- For best results, use the Percona version of MySQL! http://www.percona.com/software/percona-server/
CREATE TABLE `bookmarks` (
`id` int(11) NOT NULL,
`url` mediumtext, -- verbatim URL (may differ from actual URL referenced by url_id)