Skip to content

Instantly share code, notes, and snippets.

@coder-mike
coder-mike / 0.readme.md
Last active May 26, 2022
A toy example to illustrate how callback-based async code might look in Microvium
View 0.readme.md

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.

View keybase.md

Keybase proof

I hereby claim:

  • I am coder-mike on github.
  • I am michaelhunter (https://keybase.io/michaelhunter) on keybase.
  • I have a public key ASAzrQgBaWpLd78yXs4yB9oY9kiuojmrPvXQlW4-PXLNnwo

To claim this, I am signing this object:

View io-class-pattern.md

I/O class pattern

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

Overview

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
coder-mike / CopyNonDups.py
Last active Aug 29, 2015
Script to copy files to a destination if they aren't already there
View CopyNonDups.py
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)')