Skip to content

Instantly share code, notes, and snippets.

View r2abreu's full-sized avatar
🇻🇪

Arturo Abreu r2abreu

🇻🇪
View GitHub Profile
@r2abreu
r2abreu / index.ts
Created January 23, 2024 15:30
concatenation
import { PathLike, readFile, appendFile } from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const files = process.argv.slice(2);
/**
@r2abreu
r2abreu / index.mjs
Last active October 7, 2022 16:56
Sequential Iterator Pattern
/**
* Example of the iterator pattern described in Node.js Design Patterns.
* @see https://gist.github.com/lmammino/ac91a7bde88c0f6c6962268d67e3ffbe
* @see https://www.nodejsdesignpatterns.com/
*
* "The Sequential Iterator pattern:
* execute a list of tasks in sequence by creating an iterable function, which
* invokes the next available task in the collection and makes sure to invoke
* the next step of the interaction when the current tasks completes."
*
@r2abreu
r2abreu / index.mjs
Last active September 28, 2022 16:33
04-playing-with-errors
import { EventEmitter } from "events";
(function (number, callback) {
const EMITTER = new EventEmitter;
const MILLISECONDS_INTERVAL = 50;
const TIMESTAMP_ERROR = new Error('Timestamp is divisile by 5');
let ticks = 0;
let elapsedTimeInMilliseconds = 0;
let intervalID;
@r2abreu
r2abreu / index.mjs
Last active September 28, 2022 16:24
03-a-simple-modification
import { EventEmitter } from "events";
(function (number, callback) {
const EMITTER = new EventEmitter;
const MILLISECONDS_INTERVAL = 50;
let ticks = 0;
let elapsedTimeInMilliseconds = 0;
let intervalID;
function start() {
@r2abreu
r2abreu / index.mjs
Last active September 28, 2022 16:25
02-ticker
import { EventEmitter } from "events";
(function (number, callback) {
const EMITTER = new EventEmitter;
const MILLISECONDS_INTERVAL = 50;
let ticks = 0;
let elapsedTimeInMilliseconds = 0;
let intervalID;
function start() {