This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
copy from: https://www.jianshu.com/p/de33e6d9d880 | |
*/ | |
using System; | |
using System.Globalization; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// modified from: https://github.com/ConardLi/ConardLi.github.io/blob/master/demo/deepClone/src/clone_6.js | |
// discussion at: https://segmentfault.com/a/1190000020255831 | |
// what has changed: use loop instead of recursion | |
const mapTag = '[object Map]'; | |
const setTag = '[object Set]'; | |
const arrayTag = '[object Array]'; | |
const objectTag = '[object Object]'; | |
const argsTag = '[object Arguments]'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// original article: http://www.cnblogs.com/CodeBear/p/10508880.html | |
(()=>{ | |
class Node{ | |
constructor(name, weight){ | |
this.name = name; | |
this.weight = weight; | |
this.runtimeWeight = weight; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function() { | |
console.clear(); | |
class Task { | |
constructor(func, id) { | |
this._func = func; | |
// GUID generate method comes from: https://stackoverflow.com/a/2117523/903505 | |
this.id = id !== void(0) ? id : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c=>(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); | |
this.promise = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
class Application { | |
constructor() { | |
this.middlewares = []; | |
} | |
use(func) { | |
this.middlewares.splice(0, 0, func); | |
} | |
async execute() { | |
await this.middlewares.reduce((a, b) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application { | |
constructor() { | |
this.middlewares = []; | |
} | |
use(func) { | |
this.middlewares.push(func); | |
} | |
execute() { | |
let stack = []; | |
let idx = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FixSizedObjectPool<T> | |
{ | |
protected Func<T> Generator; | |
protected ConcurrentBag<T> ObjectBag; | |
protected int MaxSize; | |
protected long createdInstanceCount = 0; | |
protected SemaphoreSlim Pool; | |
public FixSizedObjectPool(Func<T> objectGenerator, int maxSize) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(()=>{ | |
function *fullCombination(array) { | |
function *gen(array, prefix) { | |
if (array.length === 0) { | |
yield prefix; | |
} else { | |
yield*gen(array.slice(1), [...prefix, array[0]]); | |
yield*gen(array.slice(1), [...prefix]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BigNumber = (()=>{ | |
// scale numbers represented in array format up/down by 10 to eliminate decimals | |
function alignArrayNumbers(arr1, decimalPos1, arr2, decimalPos2) { | |
var diff = Math.abs(decimalPos1 - decimalPos2); | |
var a1 = arr1.slice() | |
, a2 = arr2.slice(); | |
if (decimalPos1 > decimalPos2) { | |
a2 = [...a2, ...Array(decimalPos1-decimalPos2).fill(0)]; | |
} else if (decimalPos1 < decimalPos2) { | |
a1 = [...a1, ...Array(decimalPos2-decimalPos1).fill(0)]; |
NewerOlder