Skip to content

Instantly share code, notes, and snippets.

View tanem's full-sized avatar
🇳🇿
™️

Tane Morgan tanem

🇳🇿
™️
View GitHub Profile
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;
}
// 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(){
// 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"
Function.prototype.cached = function(){
// grab the calling function
var originalFunction = this;
// add a cache attribute
originalFunction["cache"] = {};
return function() {
/* --> 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);
*/
@tanem
tanem / gist:498b6f8f7266fd59f0f0
Last active August 29, 2015 14:02
object linking with Object.create()
var Animal = {
sayHello: function(){
console.log('Hello from ' + this.name);
}
};
var Cat = Object.create(Animal);
Cat.init = function(name){
this.name = name;
};
@tanem
tanem / fix-deps.js
Created June 11, 2018 04:23
install fixed versions of currently installed deps
// 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()
// 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 =>