This file contains hidden or 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 _search(parents, path, child, results, keysToSearch, valuesToSearch) { | |
for (const [k, { value: v }] of Object.entries(Object.getOwnPropertyDescriptors(child))) { | |
path[path.length] = String(k); | |
if (typeof v === "object") { | |
if (v != null && !parents.has(v)) { | |
parents.add(v); | |
try { | |
_search(parents, path, v, results, keysToSearch, valuesToSearch); | |
} catch(err) { return console.error("Stack limit reached at: " + path.join(" -> ")); } | |
} |
This file contains hidden or 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 Xhr { | |
constructor(opts) { | |
this.options = opts; | |
} | |
then(resolve, reject) { | |
this.xhrPool.add([this.options, resolve, reject]); | |
} | |
} | |
Object.defineProperty(Xhr.prototype, "xhrPool", { |
This file contains hidden or 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
using System; | |
using System.Reflection; | |
using System.ComponentModel; | |
namespace EnumTest | |
{ | |
[Flags] | |
public enum Longs : long | |
{ | |
[Description("1 bit")] |
This file contains hidden or 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 ReusablePromise { | |
constructor() { | |
this.executor = this._executor.bind(this); | |
this.resolve = | |
this.reject = | |
this.root = | |
this.args = | |
this.method = null; | |
} | |
setup(root, method, ...args) { |
This file contains hidden or 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
"use strict"; | |
const { abs, atan2, round, sqrt, cos, sin } = Math; | |
const vectorRe = /(?<x>\d*\.?\d*)\s*,?\s*(?<y>\d*\.?\d*)?\s*,?\s*(?<z>\d*\.?\d*)?/; | |
function num(n, d) { | |
return typeof n !== "undefined" ? parseFloat(n) : d; | |
} | |
function parseArgs(x, y, z) { | |
const { length } = arguments; |
This file contains hidden or 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
"use strict"; | |
class Optional { | |
constructor(value, isError) { | |
this._value = value; | |
this._ok = !isError; | |
} | |
[Symbol.toPrimitive](hint) { | |
switch (hint) { | |
case "number": return this._ok ? 1 : 0; |
This file contains hidden or 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
const fs = require("fs"); | |
const readline = require("readline"); | |
// https://gist.github.com/friendlyanon/afd5a18811c540bc8bcf3f40560d4c74 | |
const Queue = require("./queue"); | |
class _Readline { | |
constructor(stream) { | |
this.clear(); | |
(stream | |
.on("line", l => this.feed(l)) |
This file contains hidden or 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
"use strict"; | |
const fs = require("fs"); | |
// https://gist.github.com/friendlyanon/afd5a18811c540bc8bcf3f40560d4c74 | |
const Queue = require("./queue"); | |
function nodeCb(error, result) { | |
const { resolve, reject } = this; | |
this.data = | |
this.resolve = | |
this.reject = null; |
This file contains hidden or 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
const luhnLookup = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]; | |
// prerequisite: str is a numeric string | |
function luhn(str) { | |
let sum = 0, i, j = (i = str.length + 1) - 1; | |
while (i > 1) sum += str.charCodeAt(i -= 2) - 48; | |
while (j > 1) sum += luhnLookup[str.charCodeAt(j -= 2) - 48]; | |
return !(sum % 10); | |
} |
This file contains hidden or 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
if (!(Array.hasOwnProperty("from") && typeof Array.from === "function")) { | |
Array.from = function(arrayLike) { | |
var result, i, len, mapFn, thisArg; | |
if (arrayLike == null) { | |
throw new TypeError("Array.from requires an array-like object - not null or undefined"); | |
} | |
if (arguments.length > 1) { | |
if (typeof (mapFn = arguments[1]) !== "function") { | |
throw new TypeError("Array.from: when provided, the second argument must be a function"); | |
} |