Skip to content

Instantly share code, notes, and snippets.

View upbit's full-sized avatar

Zhou Hao upbit

  • China
View GitHub Profile
@upbit
upbit / key_binding.json
Created January 7, 2017 02:32
Sublime Text 2/3 Home/End binding for MacOS
[
{
"keys": [ "home" ],
"command": "move_to",
"args": { "to": "bol" }
},
{
"keys": [ "end" ],
"command": "move_to",
"args": { "to": "eol" }
@upbit
upbit / deprecated_func.py
Created March 10, 2017 02:32
@deprecated define for Python
#!/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
@upbit
upbit / 17173_hot_games.py
Created March 23, 2017 15:03
游戏和解说名提取
#!/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'
@upbit
upbit / channel_test.go
Created October 26, 2017 13:19
Go: wait timeout for multi requests
package usecases
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
type ChanMessage interface {
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 / HowTo.md
Last active October 8, 2018 10:49
XCode codesign on jailbreak devices

修改XCode配置文件

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/

SDKSettings.plist

> CODE_SIGNING_REQUIRED: NO
> ENTITLEMENTS_REQUIRED: NO
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
import time
class Timer(object):
def __init__(self, verbose=False):
self.verbose = verbose
def __enter__(self):
self.start = time.time()
return self
@upbit
upbit / maps.go
Created May 7, 2020 02:53
GC pause for maps
package main
import (
"fmt"
"os"
"runtime"
"time"
)
// Results of this program on my machine: (macos, go 1.14):
@upbit
upbit / filter.go
Created May 12, 2020 03:49
Filter API中对象池的
// 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