Skip to content

Instantly share code, notes, and snippets.

View xinlc's full-sized avatar
🌴
On vacation

Richard Xin xinlc

🌴
On vacation
View GitHub Profile
@xinlc
xinlc / 0_reuse_code.js
Created May 19, 2017 08:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@xinlc
xinlc / aspect.js
Created May 23, 2017 01:46
js AOP 实现AOP,提供before和after通知
/**
* js AOP
* 实现AOP,提供before和after通知
* @author Leo
*/
!function(global, undefined){
var aspect = function(){};
//aop核心实现
@xinlc
xinlc / BigDecimal.js
Last active March 6, 2021 01:33
JavaScript高精度计算
//除法函数,用来得到精确的除法结果
//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用:accDiv(arg1,arg2)
//返回值:arg1除以arg2的精确结果
function accDiv(arg1, arg2) {
var t1 = 0,
t2 = 0,
r1, r2;
try {
t1 = arg1.toString().split(".")[1].length
@xinlc
xinlc / Node-Thunkify.js
Created January 18, 2018 03:08
Turn a regular node function into one which returns a thunk
// node-Thunkify
function thunkify(fn) {
return function() {
var args = new Array(arguments.length);
var ctx = this;
for (var i = 0; i < args.length; ++i) {
args[i] = arguments[i];
}
function co(gen) {
var ctx = this;
return new Promise(function(resolve, reject) {
if (typeof gen === 'function') gen = gen.call(ctx);
if (!gen || typeof gen.next !== 'function') return resolve(gen);
onFulfilled();
function onFulfilled(res) {
var ret;
@xinlc
xinlc / ProxyPolyfill.js
Created May 12, 2018 04:19
ES7 Proxy Polyfill
var dfGetter=function(target, property, receiver){
return target[property];
};
var dfSetter=function(target, property, value, receiver){
return target[property]=value;
};
const _Proxy = function(target, handler){
var me=this;
if(!handler.get){
@xinlc
xinlc / ArrayRemove.js
Last active May 15, 2018 08:14
JS 数组删除元素
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// 移除数组中的第二项
// array.remove(1);
@xinlc
xinlc / MixIn.js
Created June 15, 2018 06:53
Mixin 指的是多个对象合成一个新的对象,新对象具有各个组成成员的接口.
function mix(...mixins) {
class Mix {}
for (let mixin of mixins) {
copyProperties(Mix, mixin); // 拷贝实例属性
copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性
}
return Mix;
}
@xinlc
xinlc / topview.js
Created January 28, 2019 07:43 — forked from mactive/topview.js
rn-topview
/**
* mactive@gmail.com
* 2017-05-08
*/
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
@xinlc
xinlc / ClassUtil.java
Created April 19, 2019 03:58
取得某个接口下所有实现这个接口的类
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;