Skip to content

Instantly share code, notes, and snippets.

def gen_user_psw(auth):
from urllib import quote
returned = ''
if auth:
# urllib.quote 转义 @:/ 等特殊字符
# 第二个参数表示转义任何字符,默认会不转义 / 字符
user = quote(auth['username'], '')
psw = quote(auth['password'], '')
returned = '%s:%s@' % (user, psw)
return returned
@wenshin
wenshin / tranimation.js
Last active January 12, 2016 15:07
A zoom util for mobile web app
/**
* requesteAnimationFrame 兼容支持
* @reference
* http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
* @return {undefined}
*/
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
/**
* Usage:
* ```
* $ node reverseproxy.js
*
* ```
* */
const request = require('request'); // https://github.com/request/request
const http = require('http');
@wenshin
wenshin / latency.markdown
Last active October 9, 2016 05:13 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

程序员都应该知道的延迟时间

CPU L1 缓存引用 .......................... 0.5 ns
CPU 分支错误预测 ............................ 5 ns
CPU L2 缓存引用 ............................ 7 ns
互斥锁 加锁/解锁 ........................... 25 ns
内存引用 ................................. 100 ns             
Zip 压缩 1K bytes ..................... 3,000 ns  =   3 µs
1 Gbps 网络发送 2K bytes .............. 20,000 ns  =  20 µs
SSD 随机读 ........................... 150,000 ns  = 150 µs

内存连续读 1 MB 数据 .................. 250,000 ns = 250 µs

@wenshin
wenshin / cltools.sh
Created July 12, 2017 06:28 — forked from justinbellamy/cltools.sh
Install Autoconf and Automake on OS X El Capitan
#!/bin/sh
##
# Install autoconf, automake and libtool smoothly on Mac OS X.
# Newer versions of these libraries are available and may work better on OS X
#
# This script is originally from http://jsdelfino.blogspot.com.au/2012/08/autoconf-and-automake-on-mac-os-x.html
#
export build=~/devtools # or wherever you'd like to build
// https://noopac.com/{yourAccount}/{yourXiegongjiID}.pac
var yourXiegongjiID = 0; // number or string
var timestamp=Number(new Date().getTime()+Math.ceil(Math.random()*100)).toString(36);
var id=Number(yourXiegongjiID).toString(36);
function ip2int(ip) {
return ip.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0;
}
function init(){
/**
* iOS Webview 中,如果通过打开多个 Webview 来打开页面,那么跨页面的 LocalStorage 和 IndexedDB 都不会及时生效。
* 原因见 https://stackoverflow.com/questions/36332208/two-wkwebviews-share-local-storage-but-only-after-restart
* 解决方案:
* 1. 参考修改 iOS Webview 调度逻辑 https://stackoverflow.com/questions/36332208/two-wkwebviews-share-local-storage-but-only-after-restart
* 2. 使用 Native 提供的 Bridge
*/
import { isSupportKVStore, kvGetItem, kvSetItem } from '@/utils/app';
import bridge from '@/utils/bridge';
export function getEnvByKeySync<T extends keyof EnvParams>(
key: T
): EnvParams[T] {
return envParams[key];
}
export function parseUA(ua: string) {
const parsed = {
device: 'pc',
deviceModel: 'unknown',
os: 'unknown',
osVersion: 'unknown',
};
const [, , info] = ua.match(/^(Mozilla|Dalvik)\/[\d.-_]+ \(([^()]+)\)/) || [];
const ios = info.match(/(iPad|iPhone|iPod).+?OS\s+([\d._-]+)/i);
import { parseUA } from './parseUA';
test('parseUA', () => {
expect(
parseUA(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
)
).toEqual({
os: 'macOS',
osVersion: '10_15_7',