Skip to content

Instantly share code, notes, and snippets.

@Ariex
Ariex / ChineseDateTime
Created March 22, 2021 05:58
ChineseDateTime.cs
/*
copy from: https://www.jianshu.com/p/de33e6d9d880
*/
using System;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@Ariex
Ariex / clone.js
Created September 4, 2019 01:27
deep clone an object
// 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]';
// original article: http://www.cnblogs.com/CodeBear/p/10508880.html
(()=>{
class Node{
constructor(name, weight){
this.name = name;
this.weight = weight;
this.runtimeWeight = weight;
}
}
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\IISExpress]
@="Start IISExp Site Here"
"icon"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
00,46,00,69,00,6c,00,65,00,73,00,5c,00,49,00,49,00,53,00,20,00,45,00,78,00,\
70,00,72,00,65,00,73,00,73,00,5c,00,69,00,69,00,73,00,65,00,78,00,70,00,72,\
00,65,00,73,00,73,00,74,00,72,00,61,00,79,00,2e,00,65,00,78,00,65,00,00,00
[HKEY_CLASSES_ROOT\Directory\Background\shell\IISExpress\command]
@Ariex
Ariex / TaskScheduler.js
Last active September 11, 2018 01:06
a simple task scheduler
(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;
}
@Ariex
Ariex / middleware-with-async.js
Last active August 23, 2018 05:28
demo of how middleware could be implemented with async/await
(async () => {
class Application {
constructor() {
this.middlewares = [];
}
use(func) {
this.middlewares.splice(0, 0, func);
}
async execute() {
await this.middlewares.reduce((a, b) => {
@Ariex
Ariex / middleware-with-generator.js
Created August 23, 2018 05:07
demo of how middleware could be implemented with generator
class Application {
constructor() {
this.middlewares = [];
}
use(func) {
this.middlewares.push(func);
}
execute() {
let stack = [];
let idx = 0;
@Ariex
Ariex / FixSizedObjectPool.cs
Created August 15, 2018 23:33
An object pool with size fixed
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)
{
@Ariex
Ariex / full-combination.js
Created June 26, 2018 01:33
generate full combination of an array in js generator
(()=>{
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]);
}
}
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)];