Skip to content

Instantly share code, notes, and snippets.

View oldrev's full-sized avatar
💭
sleeping

Li Wei oldrev

💭
sleeping
View GitHub Profile
@oldrev
oldrev / cancellable-promise-demo.ts
Last active December 18, 2020 12:10
A cancellable Promise with timeout for JS/TS
// A cancellable Promise with timeout for JS/TS
class OperationCancelledError extends Error {
constructor(reason: string = '') {
super(reason);
Object.setPrototypeOf(this, OperationCancelledError.prototype);
}
}
@oldrev
oldrev / fixedpoint-pid.c
Created July 25, 2019 00:12
Fixed-Point PID Algorithm
// Fixed-Point PID Algorithm
// Ported from: https://gist.github.com/bradley219/5373998
// Author: Li "oldrev" Wei <oldrev@gmail.com>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#define FIXED32_Q (16)
@oldrev
oldrev / tsast2lambdas.ts
Created January 10, 2018 08:00
Typescript Expression Tree to Lambda Expression
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) })
//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;
}
#encoding: utf-8
# Orchard Language Package Cleanner
# Author: Wei "oldrev" Li <liwei@sandwych.com>
# License: New BSD
import sys, os, shutil
LOCAL = 'zh-CN'
@oldrev
oldrev / rmb_upper.py
Last active April 30, 2020 06:18
转换人民币大写 Python 版
#encoding: utf-8
'''
中文互联网上迄今为止实现最正确、代码最漂亮且效率最高的大写人民币金额转换代码
作者:李维 <oldrev@gmail.com>
版权所有 (c) 2013 李维。保留所有权利。
本代码基于 BSD License 授权。
'''
from io import StringIO
import math
@oldrev
oldrev / RmbUpperConverter.cs
Last active December 23, 2015 12:09
中文互联网上迄今为止实现最正确、代码最漂亮且效率最高的大写人民币金额转换代码
/** 中文互联网上迄今为止实现最正确、代码最漂亮且效率最高的大写人民币金额转换代码
* 作者:李维 <oldrev@gmail.com>
* 版权所有 (c) 2013 昆明维智众源企业管理咨询有限公司。保留所有权利。
* 本代码基于 BSD License 授权。
* */
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;