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'; | |
const roll = pattern => { | |
const samples = []; | |
let counter = 0; | |
for(;;){ | |
if (samples.length >= pattern.length) { | |
samples.shift(); | |
} | |
const sample = Math.floor(Math.random() * 6) + 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
'use strict'; | |
const AWS = require('aws-sdk'); | |
let profile = process.env.LAMBDA_TASK_ROOT && process.env.AWS_EXECUTION_ENV ? '' : 'default'; | |
const profileIndex = process.argv.indexOf('--profile'); | |
if (profileIndex > 0 && profileIndex + 1 < process.argv.length) { | |
profile = process.argv[profileIndex + 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
'use strict'; | |
const iterate = async function*(client) { | |
const params = {MaxItems: '100'}; | |
for (;;) { | |
const data = await client.listDistributions(params).promise(), | |
list = data.DistributionList, | |
items = list.Items; | |
if (items) { | |
yield items; |
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'; | |
const List = require('./List'); | |
class Cache { | |
constructor(capacity = 10) { | |
this.capacity = capacity; | |
this.size = 0; | |
this.list = new List(); | |
this.dict = {}; |
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'; | |
const zig = tree => { | |
const newTree = tree.l, | |
parent = (newTree.p = tree.p); | |
if (parent) { | |
if (parent.l === tree) parent.l = newTree; | |
else parent.r = newTree; | |
} | |
tree.p = newTree; |
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'; | |
class ListNode { | |
constructor() { | |
this.prev = this.next = this; | |
} | |
} | |
const pop = head => { | |
const rest = head.next; |
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'; | |
// using heap implementation from https://github.com/heya/ctr under the BSD-3 license | |
class Heap { | |
constructor(less = (a, b) => a < b, arrayLike = []) { | |
this.less = less; | |
this.array = Heap.make(Array.from(arrayLike), this.less); | |
} |
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'; | |
// Loosely based on JSONx: https://tools.ietf.org/html/draft-rsalz-jsonx-00 | |
const escapeValueDict = {'&': '&', '<': '<'}; | |
const escapeValue = s => ('' + s).replace(/[&<]/g, m => escapeValueDict[m]); | |
const escapeAttrDict = {'&': '&', '<': '<', '"': '"'}; | |
const escapeAttr = s => ('' + s).replace(/[&<"]/g, m => escapeAttrDict[m]); |
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'; | |
if (process.argv.length < 3) { | |
console.log('Usage: node build-index.js inFile outFile'); | |
console.log(' All file names are relative to the project directory.') | |
console.log('Example: node build-index.js src/index.html docs/index.html'); | |
process.exit(1); | |
} | |
const fs = require('fs'); |
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'; | |
const {Readable} = require('stream'); | |
const merge = (s1, s2) => { | |
s1.pause(); | |
s2.pause(); | |
let item1 = null, | |
item2 = null, |