Skip to content

Instantly share code, notes, and snippets.

@blakeyoder
blakeyoder / forloop_stagger.js
Created February 6, 2019 18:26
Stagger execution of a for loop
const items = [1, 2, 3, 4, 5];
let promise = Promise.resolve();
for (let i = 0; i < items.length; i++) {
promise = promise.then(() => {
console.log(items[i]);
return new Promise((resolve) => {
setTimeout(resolve, 500);
});
});
@blakeyoder
blakeyoder / map2json.js
Created November 12, 2018 20:16
Map to JSON
mapToJson = (inputMap) => {
if (!(inputMap instanceof Map)) {
throw new Error(`${inputMap} is not a valid Map`);
}
const outputObj = {}
inputMap.forEach((k, v) => {
return outputObj[v] = k;
});
return outputObj;
@blakeyoder
blakeyoder / stackoverlow.md
Last active November 27, 2017 21:19
Helpful Stackoverflow links
@blakeyoder
blakeyoder / python.md
Last active July 24, 2017 19:36
Python bits

Checking if a dictionary is empty

  • bool will return false if dict is empty
  • but wait, there's more! no need to explicitly bool cast if the object is a collection (list, dict, set, set, etc)

Truth Value Testing

What's with the with statement

  • It’s handy when you have two related operations which you’d like to execute as a pair, with a block of code in between. The classic example is opening a file, manipulating the file, then closing it
@blakeyoder
blakeyoder / snippets.md
Last active July 30, 2018 14:47
Code Snippets -- tired of re-googling everything

Keybase proof

I hereby claim:

  • I am blakeyoder on github.
  • I am blake_yoder (https://keybase.io/blake_yoder) on keybase.
  • I have a public key ASDwnaJqhdRrFGBcJT0m6JgHnEnscTvuOk_1TqGv17puogo

To claim this, I am signing this object: