This file contains hidden or 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
/** | |
* Uses Luhn algorithm to validate a numeric identifier. | |
* @param {String} identifier The identifier to validate. | |
* @return {Boolean} True if the identifier is valid, false if not. | |
*/ | |
function isValidIdentifier(identifier) { | |
var sum = 0, | |
alt = false, | |
i = identifier.length-1, |
This file contains hidden or 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
type typ(_) = | |
| Int: typ(int) | |
| String: typ(string) | |
| Pair(typ('a), typ('b)): typ(('a, 'b)); | |
let rec to_string: type t. (typ(t), t) => string = | |
(t, x) => | |
switch (t) { | |
| Int => string_of_int(x) | |
| String => |
This file contains hidden or 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 State(setup) {'use strict'; | |
return Object.assign(this || new State, setup); | |
} | |
State.diff = function diff(prev, curr) { | |
var map = {}, tmp, keys, i; | |
// accepts states as both prev, curr and curr, prev | |
if (map.isPrototypeOf.call(curr, prev)) { | |
tmp = curr; |
This file contains hidden or 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' | |
// JS treats subjects of bitwise operators as SIGNED 32 bit numbers, | |
// which means the maximum amount of bits we can store inside each byte | |
// is 7.. | |
const BITS_PER_BYTE = 7 | |
module.exports = class SparseArray { | |
constructor () { | |
this._bitArrays = [] |
This file contains hidden or 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'; | |
var Sister; | |
/** | |
* @link https://github.com/gajus/sister for the canonical source repository | |
* @license https://github.com/gajus/sister/blob/master/LICENSE BSD 3-Clause | |
*/ | |
Sister = function () { | |
var sister = {}, |
This file contains hidden or 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
// @flow | |
type WrapperFn = (...args: mixed[]) => void; | |
type CancelFn = {| | |
cancel: () => void, | |
|}; | |
type ResultFn = WrapperFn & CancelFn; | |
export default (fn: Function): ResultFn => { | |
let lastArgs: mixed[] = []; |
This file contains hidden or 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 memwatch = require('memwatch-next'); | |
const prettyBytes = require('pretty-bytes'); | |
function row(name, size, count, total) { | |
return ( | |
'| ' + | |
name.padStart(30) + | |
' | ' + | |
size.padEnd(10) + | |
' | ' + |
This file contains hidden or 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
//@flow | |
function TCROA(iterate) { | |
return function(initialValue, resolve) { | |
function next(value) { | |
setImmediate(() => iterate(value, resolve, next), 0); | |
} | |
next(initialValue); | |
} |
This file contains hidden or 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
import styled, {css} from 'styled-components' | |
const gridArea = area => area | |
? `grid-area: "${area}";` | |
: `` | |
const gridAreaMixin = css` | |
${props => gridArea(props.area)} | |
` | |
const CommonButton = styled.button` |
This file contains hidden or 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 each(obj, iter) { | |
for(var key in obj) { | |
var value = obj[key] | |
iter(value, key, obj) | |
} | |
} | |
function keys (obj) { | |
return Object.keys(obj).sort() | |
} |