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
'use strict'; | |
/** | |
* Validators are functions accepting `state` and `prop` where `state` is an object | |
* containing the entire form state, e.g. `{ email: 'email', password: 'password' }` | |
* and `prop` refers to the property on `state` to be validated. | |
* | |
* Validators are expected to return a falsy value if valid and a truthy value if | |
* invalid. This is to allow information re: the error to be returned. e.g. | |
* |
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
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | |
exports.default = Loadable; |
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
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
<style> | |
* { |
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
// node --max-old-space-size=100 --expose-gc index.js | |
const prettyBytes = require('pretty-bytes'); | |
const forceGC = () => { | |
if (global.gc) { | |
global.gc(); | |
} else { | |
console.warn('No GC hook! Start your program as `node --expose-gc file.js`.'); | |
} |
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
const closest = (values: number[], val: number) => { | |
if (!values.length) { | |
throw new VError( | |
{ info: { values, val } }, | |
'Expected values to contain at least one value' | |
); | |
} | |
return values.reduce( | |
(acc, currVal) => | |
Math.abs(acc.delta) > Math.abs(currVal - val) |
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
const work = () => { | |
for (let i = 0; i < 1000000; i++) {} | |
}; | |
const start = process.hrtime.bigint(); | |
work(); | |
const end = process.hrtime.bigint(); | |
console.log( | |
`Benchmark took ${Number(end - start) / 1000 / 1000 / 1000} seconds` | |
); |
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
// Originally from fast-memoize; updated to include `mem` and test multiple and non-primitive arguments. | |
const ora = require("ora"); | |
const Table = require("cli-table2"); | |
const debug = require("logdown")(); | |
const lruMemoize = require("lru-memoize").default; | |
const iMemoized = require("iMemoized"); | |
const Benchmark = require("benchmark"); | |
const underscore = require("underscore").memoize; | |
const lodash = require("lodash").memoize; |
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
const express = require('express'); | |
console.log(process.version); | |
const app = express(); | |
app.get('/hello', (req, res) => { | |
console.log('HANDLING REQUEST'); | |
res.setHeader('content-type', 'application/json'); | |
res.flushHeaders(); // `flushHeaders` to prevent http client from retrying and therefore invoking this handler multiple times. |