Skip to content

Instantly share code, notes, and snippets.

// 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
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. */
/**
* @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
*/
/**
* @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
*
<style>
html, body, h1 {
padding: 0;
margin: 0;
font-family: Helvetica;
box-sizing: border-box;
}
nav {
display: block;
/**
* @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;
/**
* @param {Object}
* @param {String}
* @returns {Boolean}
*/
function radixTreeIncludesString(radixTree, string) {
var pointer = radixTree,
characters = string.split(''),
char;
/**
* @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;
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},
/**
* @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';