Skip to content

Instantly share code, notes, and snippets.

"use strict";
const boxes = new WeakMap;
function Boxes() {
if (!new.target) {
return new Boxes;
}
boxes.set(Object.freeze(this), Object.seal({
list: []
}));
function* shrinkGen(s) {
let i = -1, c;
while (c = s.charCodeAt(++i)) yield c << 0 | (s.charCodeAt(++i) || 0) << 8;
}
function shrink(input) {
return String.fromCodePoint(...shrinkGen(input));
}
function* expandGen(str) {
@friendlyanon
friendlyanon / log.log
Last active June 23, 2019 21:19
Object iteration test
Please read my first comment before drawing your own conclusion and take the points stated there into consideration as well
--------------------------------------------------------------------------------
Object iteration test in node 12.2.0, v8 7.4.288.21-node.17
Let O be object with properties x = 1, y = 1, z = 1, then iterate over the values and sum them, storing the result in variable `total`
--------------------------------------------------------------------------------
O = { x: 1, y: 1, z: 1 }
// guard against circular properties built in
function flatten(array) {
const { isArray } = Array;
if (!isArray(array)) {
return [];
}
const visited = new WeakSet;
const result = [];
const stack = [array];
@friendlyanon
friendlyanon / vec3.js
Created July 28, 2018 15:11
3D Vector class
"use strict";
const { isArray } = Array
const { abs, atan2, round, sqrt, cos, sin } = Math;
function num(n, d) {
return n !== undefined ? Number(n) : d;
}
function parseArgs(x, y, z) {
if (typeof x === "object" && x !== null) {
@friendlyanon
friendlyanon / aya.mjs
Last active September 19, 2018 18:55
import { Server } from "_http_server";
const Aya = class Aya {
constructor() {
this.routes = {
GET: [],
HEAD: [],
POST: [],
PUT: [],
export function format(f) {
const argsLen = arguments.length;
if (argsLen < 2) return f;
const fLen = f.length - 1;
let str = "";
let a = 2;
let lastPos = 0;
let tempStr;
for (let i = 0; i < fLen; ++i) {
// ==UserScript==
// @id fix-old-youtube-layout
// @name Fix old Youtube layout (2018.08.17.)
// @version 1
// @namespace intermission
// @author intermission
// @description Fixes old Youtube layout (2018.08.17.)
// @match https://www.youtube.com
// @match https://www.youtube.com/*
// @run-at document-start
(function() {
"use strict";
var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url, extend, format, g;
g = (
typeof global !== "undefined" ?
global :
typeof self !== "undefined" ?
self :
typeof window !== "undefined" ?
"use strict";
var pow = Math.pow,
floor = Math.floor,
powArray = Array(54).map(function(_, i) { return pow(2, i); });
function intersection53() {
var map, key, i, j, len, mask, arr, value, n1, n2, b, r, argsLen, result;
for (map = {}, i = 0, argsLen = arguments.length; i < argsLen; ++i) {