{{ message }}

Instantly share code, notes, and snippets.

💭
sleeping

# Li Wei oldrev

💭
sleeping
Last active Dec 18, 2020
A cancellable Promise with timeout for JS/TS
View cancellable-promise-demo.ts
 // A cancellable Promise with timeout for JS/TS class OperationCancelledError extends Error { constructor(reason: string = '') { super(reason); Object.setPrototypeOf(this, OperationCancelledError.prototype); } }
Created Jul 25, 2019
Fixed-Point PID Algorithm
View fixedpoint-pid.c
 // Fixed-Point PID Algorithm // Ported from: https://gist.github.com/bradley219/5373998 // Author: Li "oldrev" Wei #include #include #include #include #define FIXED32_Q (16)
Created Jan 10, 2018
Typescript Expression Tree to Lambda Expression
View tsast2lambdas.ts
 function visitAndExpression(exprNode: any): any { const conditions = exprNode.expressions.map(function (expr: any) { return visitExpression(expr) }) return function (it: any) { return conditions.every(function (c: any) { return c(it) }) } } function visitOrExpression(exprNode: any): any { const conditions = exprNode.expressions.map(function (expr: any) { return visitExpression(expr) })
Created Nov 27, 2015
View gis_coords_convert.js
 //JS 实现的WGS84 坐标系转火星坐标系 GCJ-02 转百度坐标系 BD-09 function _transformLat(x, y) { var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0; ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0; ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0; return ret; }
Last active Aug 29, 2015
View orchard_clear.py
 #encoding: utf-8 # Orchard Language Package Cleanner # Author: Wei "oldrev" Li # License: New BSD import sys, os, shutil LOCAL = 'zh-CN'
Last active Apr 30, 2020

View rmb_upper.py
 #encoding: utf-8 ''' 中文互联网上迄今为止实现最正确、代码最漂亮且效率最高的大写人民币金额转换代码 作者：李维 版权所有 (c) 2013 李维。保留所有权利。 本代码基于 BSD License 授权。 ''' from io import StringIO import math
Last active Dec 23, 2015

View RmbUpperConverter.cs
 /** 中文互联网上迄今为止实现最正确、代码最漂亮且效率最高的大写人民币金额转换代码 * 作者：李维 * 版权所有 (c) 2013 昆明维智众源企业管理咨询有限公司。保留所有权利。 * 本代码基于 BSD License 授权。 * */ using System; using System.Collections.Generic; using System.Text; using System.Diagnostics;