Skip to content

Instantly share code, notes, and snippets.

Avatar

Zhou Hao upbit

View GitHub Profile
@upbit
upbit / README.md
Last active Aug 2, 2021 — forked from ZipFile/README.md
Pixiv OAuth Flow (with Selenium)
View README.md

Retrieving Auth Token (with Selenium)

  1. Setup, install Selenium/ChromeDriver
pip install selenium
# download chromedriver from https://chromedriver.storage.googleapis.com/index.html?path=91.0.4472.101/
# eg: wget https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_mac64.zip && unzip chromedriver_mac64.zip
@upbit
upbit / jsonp-proxy.py
Created Jul 1, 2020 — forked from netj/jsonp-proxy.py
A primitive JSON-P proxy in Python compatible to node-jsonp-proxy (support python3)
View jsonp-proxy.py
#!/usr/bin/env python
# A very primitive JSON-P proxy in Python
# Derived from Patric Fornasier's Blog: http://patforna.blogspot.com/2009/03/jsonp-proxy-server.html
# Made compatible with node-jsonp-proxy: https://github.com/clintandrewhall/node-jsonp-proxy
import sys
import re
import urllib
if sys.version_info >= (3, 0):
from http.server import BaseHTTPRequestHandler, HTTPServer
@upbit
upbit / filter.go
Created May 12, 2020
Filter API中对象池的
View filter.go
// Filter 注册的filter,用于在server端过滤数据并提供高性能查询
type Filter struct {
KeyFileds []string
FilterStr string // 更新无极数据时用到的,注册的filter条件
Template interface{} // 返回数据类型模板
// objStore 用于Filter后数据的存储
objStore map[string]interface{}
objStoreMutex *sync.RWMutex
dataVersion int // 当前内存中无极数据的版本
stat *Stat
@upbit
upbit / maps.go
Created May 7, 2020
GC pause for maps
View maps.go
package main
import (
"fmt"
"os"
"runtime"
"time"
)
// Results of this program on my machine: (macos, go 1.14):
View timer.py
import time
class Timer(object):
def __init__(self, verbose=False):
self.verbose = verbose
def __enter__(self):
self.start = time.time()
return self
View chunks.py
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
View faster_random_string.go
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)
func RandStringBytesMaskImpr(n int) string {
b := make([]byte, n)
// A rand.Int63() generates 63 random bits, enough for letterIdxMax letters!
@upbit
upbit / channel_test.go
Created Oct 26, 2017
Go: wait timeout for multi requests
View channel_test.go
package usecases
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
type ChanMessage interface {
@upbit
upbit / 17173_hot_games.py
Created Mar 23, 2017
游戏和解说名提取
View 17173_hot_games.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
def fetch_17173_game_list():
url = 'http://www.17173.com'
r = requests.get(url)
r.encoding = 'utf-8'
View deprecated_func.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import warnings
import functools
# http://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically
def deprecated(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emmitted