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 debugBuffer = [] | |
const savepoints = {} | |
const debug = function (msg) { | |
// using the full UTC string is a bit heavy handed perhaps; only minutes, seconds and ms would be quite enough, or just the timestamp in ms | |
debugBuffer.push(`${new Date().toUTCString()} ${msg}`) | |
} | |
const setSavepoint = function (savepoint) { | |
savepoints[savepoint] = debugBuffer.length |
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 debug = function (debugBuffer, msg) { | |
// using the full UTC string is a bit heavy handed perhaps; only minutes, seconds and ms would be quite enough, or just the timestamp in ms | |
debugBuffer.push(`${new Date().toUTCString()} ${msg}`) | |
} | |
const spillDebugBeans = function (debugBuffer) { | |
debugBuffer.forEach(msg => { console.log(`DEBUG: ${msg}`) }); | |
}// spillDebugBeans | |
const calculateSums = async function (sums) { |
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
# a global variable | |
WELCOME_ROOT=Hello | |
# invoke this function with two arguments: | |
# 1. (FROM_VAR) the name of the greeter | |
# 2. (TO_VAR) the name of the greetee | |
# this function returns a welcoming message | |
get_welcoming_message() | |
{ | |
FROM_VAR=$1 |
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 sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds))) | |
} | |
const lg = (msg) => { | |
const d = new Date() | |
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`) | |
} | |
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements |
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 sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds))) | |
} | |
const lg = (msg) => { | |
const d = new Date() | |
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`) | |
} | |
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements |
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 sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds))) | |
} | |
const lg = (msg) => { | |
const d = new Date() | |
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`) | |
} | |
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements |
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
// pancake party for my son's birthday | |
// I have promised him pancakes. Each pancake has to be baked, decorated (syrup, sugar, jam, ..) and sliced (in bite size sections) | |
const numberOfGuests = 8 | |
// assuming each guest eats exactly three pancakes | |
const totalNumberOfPancakes = numberOfGuests * 3 | |
const numberOfPans = 1 | |
// times in milliseconds | |
const timeToBakeOnePancake = 3000; |
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 sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds))) | |
} | |
const lg = (msg) => { | |
const d = new Date() | |
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`) | |
} | |
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements |
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
// asynchronous generator - read in await for..of loop | |
const sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, milliseconds)) | |
} | |
const lg = (msg) => { | |
const d = new Date() | |
console.log(`${d.getSeconds()}:${d.getMilliseconds()} - ${msg}`) | |
} | |
const alphabet = async 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
var countriesDocumentURL = "https://raw.githubusercontent.com/mledoze/countries/master/countries.json" | |
request(countriesDocumentURL, async function (error, response, body) { | |
var countries = JSON.parse(body) | |
// get unique region values (see: https://codeburst.io/javascript-array-distinct-5edc93501dc4) | |
// take all elements in the countries array, for each of them: take the region element; create a Set of all the resulting region values (a Set contains unique elements) | |
var regions = [...new Set(countries.map(country => country.region))] | |
var subregions = [...new Set(countries.map(country => country.subregion))] | |
// see https://stackoverflow.com/questions/39837678/why-no-array-prototype-flatmap-in-javascript for this flatMap function | |
const flatMap = (f, xs) => |