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
// Credit: https://www.learnrxjs.io/operators/error_handling/retrywhen.html. | |
import { throwError, timer } from 'rxjs'; | |
import { ajax } from 'rxjs/ajax'; | |
import { finalize, mergeMap, retryWhen } from 'rxjs/operators'; | |
const genericRetryStrategy = ({ | |
maxRetryAttempts = 3, | |
scalingDuration = 5000 | |
} = {}) => errors => |
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
// Usage: `node fix-deps.js` | |
// Pre-req: Ensure `save-prefix ""` is set in `.yarnrc`. | |
const {exec} = require('child_process') | |
// `yarn ls --depth=0` doesn't quite do what we want, see: | |
// https://github.com/yarnpkg/yarn/issues/3569#issuecomment-362832264. | |
exec('npm ls --depth 0', (_, stdout) => { | |
const deps = stdout | |
.trim() |
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 Animal = { | |
sayHello: function(){ | |
console.log('Hello from ' + this.name); | |
} | |
}; | |
var Cat = Object.create(Animal); | |
Cat.init = function(name){ | |
this.name = name; | |
}; |
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
/* --> 1 | |
document.getElementById('the_div').addEventListener( | |
'click', function(){ log('the_div!') }, true); | |
document.getElementById('the_list').addEventListener( | |
'click', function(){ log('the_list!') }, false); | |
document.getElementById('the_item').addEventListener( | |
'click', function(){ log('the_item!') }, true); | |
*/ |
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
Function.prototype.cached = function(){ | |
// grab the calling function | |
var originalFunction = this; | |
// add a cache attribute | |
originalFunction["cache"] = {}; | |
return function() { | |
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
// 1. Write a class to support the following code: | |
function Person(name) { | |
this.name = name; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); | |
console.log(thomas.name); // --> "Thomas" |
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
// Wrap the following code in a closure and export only the "countdown" function. | |
var countdown = (function(){ | |
var index; | |
function log(){ | |
console.log(index); | |
} | |
function iterate(){ |
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
function logCar(car) { | |
console.log("I'm a " + car.color + " " + car.make); | |
} | |
logCar({ color: 'blue', make: 'BMW' }); | |
function Car(make, color) { | |
this.make = make; | |
this.color = color; | |
} |