Skip to content

Instantly share code, notes, and snippets.

coder-mike / Measure cost of async in node.js
Last active November 5, 2022 22:52
Measure cost of async in node
View Measure cost of async in node.js
// node --expose-gc script.js
const before = process.memoryUsage().heapUsed;
const arr = [];
const count = 1 * 1024 * 1024;
const never = new Promise(() => {});
coder-mike / _ Closure Size
Last active October 21, 2022 20:40
Closure size measurements
View _ Closure Size

Closure size measurements

Open for details.

coder-mike /
Last active May 26, 2022 22:02
A toy example to illustrate how callback-based async code might look in Microvium

Toy Example of callback-based code in Microvium

See the corresponding blog post here.

The main objective here is to write a sendToServer function that is an example of an operation that hypothetically takes 3 steps to complete: powering on the modem, connecting to the server, and sending the data. In the spirit of writing non-blocking, single-threaded code, this uses callbacks to trigger the next step when the previous completes.

This example is written to run on the Microvium JavaScript engine, so it doesn't use any features that Microvium doesn't support.

The example is not fully comprehensive. For example, it doesn't include error checking or timeouts. It doesn't check if the modem is powered on, but just powers it on each time (it also doesn't power it off). But it's easy to imagine how modem.powerOn() could be changed to if (alreadyPoweredOn) ... , etc.


Keybase proof

I hereby claim:

  • I am coder-mike on github.
  • I am michaelhunter ( on keybase.
  • I have a public key ASAzrQgBaWpLd78yXs4yB9oY9kiuojmrPvXQlW4-PXLNnwo

To claim this, I am signing this object:

coder-mike /
Created February 21, 2019 22:15 — forked from phoddie/
For Ecma TC53

I/O class pattern

Copyright 2018 Moddable Tech, Inc.
Peter Hoddie
Patrick Soquet
Updated December 17, 2018


The I/O class pattern is designed to be applied to many different interfaces. These include digital, analog input, SPI, I2C, serial, TCP socket, UDP socket, etc. Each of these defines a class pattern for the interface (e.g. a Digital class pattern) that is a logical subclass of the I/O class pattern.

The I/O class pattern assumes read and write operations will not block for significant periods of time (this is deliberately not quantified). The model for this is non-blocking network sockets.

coder-mike /
Last active August 29, 2015 14:07
Script to copy files to a destination if they aren't already there
import hashlib
import os
import sys
import argparse
import shutil
import time
parser = argparse.ArgumentParser(description='Copies files to a primary destination directory when they aren\'t already in one of the destination directories')
parser.add_argument('source', help='Source directory to copy files from')
parser.add_argument('primdest', help='The primary destination (where to copy files to)')