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'; | |
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 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
var TWO_PI = 2 * Math.PI; | |
function tmpl (template, dict) { | |
return template.replace(/\$\{([^\}]*)\}/g, function (_, name) { | |
return dict[name]; | |
}); | |
} | |
function makeSegment (args, options) { | |
// args is {startAngle, angle, index, className} |
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'; | |
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 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 ListHead { | |
constructor(head = null, next = 'next', prev = 'prev') { | |
if (head instanceof ListHead) { | |
({nextName: this.nextName, prevName: this.prevName, head: this.head} = head); | |
return; | |
} | |
this.nextName = next; | |
this.prevName = prev; |
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
let flag; | |
const detectWebp = () => { | |
if (typeof flag == 'boolean') return flag; | |
const canvas = document.createElement('canvas'); | |
flag = !!(canvas.getContext && canvas.getContext('2d') && /^data:image\/webp;/.test(canvas.toDataURL('image/webp'))); | |
return flag; | |
}; | |
export default detectWebp; |
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'; | |
// 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 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 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 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 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; |