Skip to content

Instantly share code, notes, and snippets.

View manekinekko's full-sized avatar
:octocat:
Check me out on BlueSky @wassim.dev

Wassim Chegham manekinekko

:octocat:
Check me out on BlueSky @wassim.dev
View GitHub Profile
@StevenACoffman
StevenACoffman / async javascript.md
Last active November 9, 2017 13:09
Async Await in 7 seconds

Async / Await in 7 seconds

by Wassim Chegham (@manekinekko)

From this awesome animation, originally from this tweet

Callbacks (continuation passing style)

getData( a => {
	getMoreData(a, b => {
var kb = require("ble_hid_keyboard");
NRF.setServices(undefined, { hid : kb.report });
var reset_timer;
var next = "n";
var prev = "p";
function sendCharNext(){
if (next == next.toLowerCase()){
sk = 0;
} else {
@jkrems
jkrems / es-module-history.md
Last active March 16, 2025 13:43
History of ES modules

Modules - History & Future

History

function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
@ceejbot
ceejbot / esm_use_cases.md
Last active April 3, 2018 04:21
ESModule use cases, a list in progress

ES module use cases

  • Alice is writing a new library, and she is excited to use the new ES6 syntax. However, she would like to use an older but still good package she found on npm, that exports its interface using CommonJS. She does so easily after reading the NodeJS documentation on how to do this.

  • Bob is updating a module for his work, and he needs to support existing CommonJS-using codebases as well as a new project that prefers to stick with ES6 for static analysis reasons. He publishes a package that exports both kinds of interfaces.

  • Carol is updating her popular code coverage reporting tool for the new world. She uses the ESM loader hooks to instrument test code as it is imported so she can get code coverage reporting on par with what she has for CommonJS.

  • David is writing a transpiler. He writes a custom hook that transpiles source as it's loaded from his language to JavaScript.

// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
@sinedied
sinedied / fastread.js
Last active June 5, 2022 15:29
Fast reading experimentation
// Usage: fastRead('Lorem ipsum dolor sit amet')
function fastRead(text, left = '<b>', right = '</b>') {
return text?.replace(/[A-Za-zÀ-ÖØ-öø-ÿ0-9]+/gm, (word) => {
const split = word.length > 3 ? Math.ceil(word.length / 2) : 1;
return left + word.substring(0, split) + right + word.substring(split);
});
}