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 executeAllPromises(promises) { | |
// Wrap all Promises in a Promise that will always "resolve" | |
var resolvingPromises = promises.map(function(promise) { | |
return new Promise(function(resolve, reject) { | |
var payload = new Array(2); | |
promise.then(function(result) { | |
payload[0] = result; | |
}) | |
.catch(function(error) { | |
payload[1] = error; |
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
// Fibonacci numbers | |
/* extended version */ | |
function f(n) { | |
if (n === 0) { | |
return 0; | |
} else if (n === 1) { | |
return 1; | |
} else { | |
return f(n - 1) + f(n - 2); |
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
const Combinatorics = require('js-combinatorics'); | |
const n = ['A', 'B', 'C', 'D']; | |
const k = 2; | |
const generator = Combinatorics.bigCombination(n, k); | |
const combinations = generator.toArray().length; | |
console.log(`Possible combinations: ${combinations}`); // "Possible combinations: 6" |
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
const winston = require('winston'); // v2.3.1 | |
winston.configure({ | |
transports: [ | |
new (winston.transports.File)({ | |
filename: './data/test.txt', | |
handleExceptions: true, | |
json: false, | |
level: 'silly', | |
maxFiles: 5, |
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
const phantom = require('phantom'); | |
/** | |
* Acts like a web browser and gets page content (also from dynamic HTML pages). | |
* @param {string} url - Page URL | |
* @returns {Promise.<string, Error>} Resolves with the page content. | |
*/ | |
module.exports = async function(url) { | |
const instance = await phantom.create(); | |
const page = await instance.createPage(); |
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
#!/usr/bin/env node | |
'use strict'; | |
const b = require('bonescript'); | |
console.log('VERSION', 2); | |
console.log(`Working directory of the Node.js process: ${process.cwd()}`); | |
const leds = ['USR0', 'USR1', 'USR2', 'USR3', 'P9_14']; |
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
const reruns = 10; | |
const delayedPromise = (iterations) => { | |
return new Promise((resolve) => { | |
const delay = 1000; | |
setTimeout(() => { | |
if (iterations > 0) { | |
iterations -= 1; | |
console.log('Iteration', iterations); | |
delayedPromise(iterations).then(resolve); |
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
const inquirer = require('inquirer'); | |
const questions = [{ | |
default: false, | |
message: 'Is this correct?', | |
name: 'isCorrect', | |
type: 'confirm', | |
}]; | |
inquirer.prompt(questions) |
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
import React from 'react'; // 16.2.0 | |
import {mount} from 'enzyme'; // 3.2.0 | |
it('does something', () => { | |
class TestInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
inputValue: 'before', | |
}; |
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 allPossibleCombinations(input, fixedLength, currentCombination) { | |
if (currentCombination.length == fixedLength) { | |
return [currentCombination]; | |
} | |
const combinations = []; | |
for (let i = 0; i < input.length; i++) { | |
combinations.push(...allPossibleCombinations(input, fixedLength, currentCombination + input[i])); | |
} |
OlderNewer