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 Enum(...names) { | |
const target = new.target ? this : names.shift(); | |
const desc = { | |
writable: false, | |
configurable: false, | |
value: null, | |
enumerable: true | |
}; |
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
// List of strings that will be chained to spell words. | |
const atoms = new Set(["ac", "al", "am", "sb", "ar", "as", "at", "ba", "bk", "be", "bi", "bh", "b", "br", "cd", "ca", "cf", "c", "ce", "cs", "cl", "cr", "co", "cu", "cm", "ds", "db", "dy", "es", "er", "eu", "fm", "f", "fr", "gd", "ga", "ge", "au", "hf", "hs", "he", "ho", "h", "in", "i", "ir", "fe", "kr", "la", "lr", "pb", "li", "lu", "mg", "mn", "mt", "md", "hg", "mo", "nd", "ne", "np", "ni", "nb", "n", "no", "os", "o", "pd", "p", "pt", "pu", "po", "k", "pr", "pm", "pa", "ra", "rn", "re", "rh", "rg", "rb", "ru", "rf", "sm", "sc", "sg", "se", "si", "ag", "na", "sr", "s", "ta", "tc", "te", "tb", "tl", "th", "tm", "sn", "ti", "w", "uub", "uuh", "uuo", "uup", "uuq", "uus", "uut", "uuu", "u", "v", "xe", "yb", "y", "zn", "zr"]); | |
// An optimization. Should be equal to the length of the longest string in the `atoms` set above. Not strictly necessary | |
const maxAtomSize = 3; | |
/* | |
USAGE: | |
createMolecule(String targetWord) -> Iterator -> Array<String> | |
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 loadScript(url) { | |
var request = new XMLHttpRequest; | |
request.open('GET', url, false); | |
request.send(); | |
eval(request.responseText); | |
} |
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 multiKey(keyGroups) { | |
let obj = {}; | |
let props = {}; | |
for (let keyGroup of keyGroups) { | |
let masterKey = keyGroup[0]; | |
let prop = { | |
configurable: true, | |
enumerable: false, |
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
/* | |
SYNTAX: | |
object Object.prototype.lazyProp(string propName, function evaluator [, object propertyDescriptorDefaults]); | |
USAGE: | |
let obj = {}; | |
obj.lazyProp('sqrtPI', () => Math.sqrt(Math.PI)) | |
.lazyProp('e4', () => Math.E ** 10); | |
// obj.sqrtPI and obj.e4 have not been calculated yet |
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
// Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign | |
// Public domain | |
if (typeof Object.assign !== 'function') { | |
Object.defineProperty(Object, 'assign', { | |
configurable: true, | |
enumerable: false, | |
writable: true, | |
// Second argument forces the `length` property to be 2, as per the spec |
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
/* | |
USAGE: | |
void removeFormatting(Element) | |
RESULT: | |
The provided element now contains a single Text node, whose value is | |
the concatenation of all the Text nodes in the original element's hierarchy | |
*/ | |
// Used internally. Empties the element and returns the concatenated text as a String |
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
/* | |
SYNTAX: | |
Generator treeIterator(Node root, int whatToShow, bool function filter(Node)) | |
- root: The parent node. It is not returned. | |
- whatToShow: Bitmask of the NodeFilter.SHOW_* static constants. Represents the types of nodes included. | |
- filter: Predicate returning whether the node given as the first argument should be included in the iteration. | |
Instead of a boolean, it may return a NodeFilter.FILTER_* static constant. | |
A return value of `true` is implicitly converted to `NodeFilter.FILTER_ACCEPT`, | |
and `false` becomes `NodeFilter.FILTER_REJECT` | |
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
#pragma once | |
#include <cmath> | |
#include <vector> | |
struct Triangle { | |
int a, b, c; | |
}; | |
inline int gcd(int a, int 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
function probablyPrime(n, k) { | |
// Always prime | |
if (n === 2 || n === 3) | |
return true; | |
// Never prime | |
if (n % 2 === 0 || n < 2) | |
return false; | |
// Write (n - 1) as 2^s * d |