Skip to content

Instantly share code, notes, and snippets.

(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);
// 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,
// 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);
(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 {
(function(global) {
var PARENT = "[[__PARENT__]]";
function Immutable(obj) {
if (obj instanceof Object) {
for (var keys = Object.keys(obj), i = 0; i < keys.length; i++) {
this[keys[i]] = obj[keys[i]];
}
}
if (obj !== false) Object.freeze(this);
// https://mozilla.github.io/server-side-tls/ssl-config-generator/
server {
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
@c7x43t
c7x43t / serialize.js
Last active April 29, 2018 11:08
serialize <input>
function serialize(form){
if (!form || form.nodeName !== "FORM") return;
var el, op, obj = {}, name, type, value, node;
for (el of form.elements) {
name=el.name;
if (name === "") continue;
type=el.type;
value=el.value;
node=el.nodeName;
if(/INPUT/.exec(node) && (/text|hidden|password|button|reset|submit/.exec(type) || /checkbox|radio/.exec(type)&&el.checked) ||
@c7x43t
c7x43t / round n to m decimals.js
Last active May 9, 2018 09:40
roundN(1.005,2) -> 1.01
function roundN(n,m){
return Math.round(n*Math.pow(10,m)+72e-16)/Math.pow(10,m);
}
.font-smoothing {
/* Adjust font size */
font-size: 100%;
-webkit-text-size-adjust: 100%;
/* Font varient */
font-variant-ligatures: none;
-webkit-font-variant-ligatures: none;
/* Smoothing */
font-smooth: always;
text-rendering: optimizeLegibility;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>compare</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>