Skip to content

Instantly share code, notes, and snippets.

(function(global) {
// Instead of looping trough all possibilities a object property lookup is used
// The object construction is in addition memoized, since it's relatively expensive
var hashFindHash = {};
function hashFind(str, hash, delimiter) {
delimiter = delimiter || ";";
if (hashFindHash.hasOwnProperty(hash)) {
return hashFindHash[hash].hasOwnProperty(str);
} else {
// subClass returns a constructor wrapper function that has all the methods in the subclass Prototype,
// while keeping the original return type's prototype
// when to use? augmenting objects generated by classes with methods.
// since it is a wrapper also native classes like Array, String, Number can safely be extended
// adding methods to returned objects is also reasonably fast this way, because only the Prototype needs to be set
function subClass(constructor, returnType, methods) {
function collector() {}
methods = methods ? methods instanceof Array ? methods : [methods] : [];
const subConstructor = function() {
const obj = constructor(...arguments);
// This is implementing a iterable WeakMap
// It has the same methods as WeakMap and in addition:
// It's keys and values are readable properties.
// It can be iterated by map and reduce, Arguments: key, value
class IterableWeakMap{
constructor(){
Object.defineProperties(this,{
keys:{
enumerable: false,
writable: true,
(function(a){function c(e,f){var g=Object.create(this);if(e instanceof Array){if(f instanceof Array)for(var h in e)g[e[h]]=f[h];else for(var h in e)g[e[h]]=f;}else if(e instanceof Object)for(var j in e)g[j]=e[j];else g[e]=f;return g=Object.create(g),Object.freeze(g),g}function*d(){for(let e in this)yield this[e]}a.Subzero=function(e){var f=this;return f[Symbol.iterator]=d,Object.defineProperty(f,"set",{value:c}),Object.freeze(f),f.set(e)}})(window);
function getEventNames() {
var doc = [];
for (var i in document) {
doc.push(i)
};
doc = doc.filter(function(i) {
var e = document[i];
return i.substring(0, 2) == 'on' && (e == null || e instanceof Function)
})
.map(s => s.replace(/^on/, ""));
Object.prototype[Symbol.iterator]=function* objectIterator(){
const keys=Object.keys(this);
for(var i=0;i<keys.length;i++) yield keys[i];
}
Statistical profiling result from isolate-0x55f6bb94e1f0-v8.log, (7139 ticks, 137 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
318 4.5% /usr/bin/node
194 2.7% /lib/x86_64-linux-gnu/libc-2.27.so
18 0.3% /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
2 0.0% [vdso]
1 0.0% /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25
@c7x43t
c7x43t / gist:935a7cbd457a16936001105cb57b5eb4
Created November 5, 2018 13:01 — forked from AndreasMadsen/gist:2693051
base64 shim [atob, btoa]
// Source: http://code.google.com/p/gflot/source/browse/trunk/flot/base64.js?r=153
/* Copyright (C) 1999 Masanao Izumo <[email protected]>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
function handler(mutations) {}
var observer = new MutationObserver(handler);
var options = {attributes: true}
observer.observe(element, options);
var html = '<div id="test_div"><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul></div>';
var parser = new DOMParser();
var wrapper = parser.parseFromString(html, "text/html"); // this is a DocumentFragment
// Polyfill for DOMParser.parseFromString to support html: https://developer.mozilla.org/de/docs/Web/API/DOMParser