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
| // Example | |
| let backoff = new Backoff({ | |
| timeout: 5000, | |
| backoffExponent: 2, | |
| attempts: 10, | |
| jitterCap: 1000 * 60 * 20 // 20 minutes | |
| }); | |
| backoff.exec(function(markAsDone, forceRetry, forceFailure) { | |
| /* Some async process that might fail, in which |
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
| backoff.exec(function(markAsDone, forceRetry, forceFailure) { | |
| /* Some async process that might fail, in which | |
| case you would want to retry. A network request is a | |
| prime example. The request will automatically retry if | |
| it reaches the timeout threshold you specified. | |
| Alternatively, you can call forceRetry(). | |
| Use markAsDone() to indicate that the process has | |
| finished succcessfully and forceFailure() to give up | |
| on the process permanently. */ |
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
| /** | |
| * @desc A function to calculate how long it will take my girlfriend | |
| * to get ready to go somewhere on a Friday night. | |
| * | |
| * @param {Number} How long she says it will take | |
| * @param {Number} How many miles away the destination is | |
| * @param {Number} How many stars the restaurant, bar, etc., has on Yelp | |
| * | |
| * @returns {Number} Actual number of minutes | |
| */ |
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
| /** | |
| * @module PubSub | |
| * @author Cody Romano | |
| * @desc A basic module for publishing and subscribing to events. It supports | |
| * retroactive publishing. In other words, subscribers can respond to events | |
| * that were broadcast before the subscribers were added. The retroactive | |
| * feature works by default, but it is optional. | |
| * | |
| * @example | |
| * |
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
| <style> | |
| html, body, h1 { | |
| padding: 0; | |
| margin: 0; | |
| font-family: Helvetica; | |
| box-sizing: border-box; | |
| } | |
| nav { | |
| display: block; |
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
| /** | |
| * @desc Convert an array of strings to a radix tree | |
| * @param {Array} | |
| * @returns {Object} | |
| */ | |
| function radixTree(stringArray) { | |
| return stringArray.reduce(function(result, string) { | |
| var characters = string.split(''), | |
| pointer = result; |
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
| /** | |
| * @param {Object} | |
| * @param {String} | |
| * @returns {Boolean} | |
| */ | |
| function radixTreeIncludesString(radixTree, string) { | |
| var pointer = radixTree, | |
| characters = string.split(''), | |
| char; |
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
| /** | |
| * @desc Convert an array of strings to a radix tree | |
| * | |
| * @param {Array} | |
| * @returns {Object} | |
| */ | |
| function radixTree(stringArray) { | |
| return stringArray.reduce(function(result, string) { | |
| var characters = string.split(''), | |
| pointer = result; |
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 getMockDelay() { | |
| return 1000 + (Math.random() * 4000); | |
| } | |
| async function getProducts() { | |
| return new Promise((resolve) => { | |
| var products = [ | |
| {title: 'Wave Runner', category: 'sports', cost: 5000}, | |
| {title: 'Mac', category: 'electronics', cost: 2000}, | |
| {title: 'Toaster', category: 'kitchen', cost: 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
| /** | |
| * @module RetroRecorder | |
| * @author Cody Romano | |
| * @desc This is just a demo to illustrate how RetroRecorder might be implemented. | |
| * Please take it with a grain of salt because it's not optimized and the Speech API | |
| * probably isn't the best implementation. | |
| */ | |
| (function(exports) { | |
| 'use strict'; |