Skip to content

Instantly share code, notes, and snippets.

View manekinekko's full-sized avatar
:octocat:
Check me out on Twitter @manekinekko

Wassim Chegham manekinekko

:octocat:
Check me out on Twitter @manekinekko
View GitHub Profile
@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);
});
}
// 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) => {
@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.

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)},
@jkrems
jkrems / es-module-history.md
Last active November 5, 2023 19:35
History of ES modules

Modules - History & Future

History

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 {
@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 => {
@Brocco
Brocco / pixel-reduce.js
Created February 8, 2017 18:03
Organizing array of [r, g, b, a, r, g, b, a] to an object array [{r, g, b, a}, {r, g, b, a}]
const pixels = ['r','g','b','a','r','g','b','a','r','g','b','a'];
const propMap = ['r', 'g', 'b', 'a'];
const rgbas = pixels.reduce((acc, curr, i) => {
const mod = i%4;
switch (mod) {
case 0:
return [...acc, {r: curr}];
default:
/* tslint:disable */
const program =
`
module "login"
go to "app/login"
fill "mgechev+18@gmail.com" in "#username"
fill "foobar" in "#password"
click "#login"
@PaulKinlan
PaulKinlan / canvasrecord.js
Last active August 9, 2022 11:55
Screen recorder in JS
(function() {
let canvas = document.querySelector('canvas');
// Optional frames per second argument.
let stream = canvas.captureStream(25);
var options = {mimeType: 'video/webm; codecs=vp9'};
let recorder = new MediaRecorder(stream, options);
let blobs = [];
function download(blob) {
var url = window.URL.createObjectURL(blob);