Skip to content

Instantly share code, notes, and snippets.

View phoddie's full-sized avatar

Peter Hoddie phoddie

View GitHub Profile
uintptr_t - integer type large enough to hold pointer
#include "stdint.h"
void *xp = // some pointer
uintptr_t xi = (uintptr_t)xp;
int *xp2 = (void *)xi;
// xp == xp2 on all systems
function tracePacket(bytes)
{
for (let i = 0; i < bytes.length; i += 16) {
let end = i + 16;
if (end > bytes.length) end = bytes.length;
for (let j = i; j < end; j++) {
let byte = bytes[j].toString(16);
if (byte.length < 2) byte = "0" + byte;
trace(byte, " ");
}

Output from xsuse on ESP8266.

June 22, 2018

Boolean: 0 bytes
Number: 0 bytes
String `String in ROM`: 0 bytes
String `fromCharCode(32)`: 12 chunk bytes = 12 bytes
String `String in ` + 'RAM': 24 chunk bytes = 24 bytes
Object {}: 0 bytes
Object {x: 1}: 2 slots = 32 bytes
@phoddie
phoddie / repl.js
Last active July 14, 2019 00:44
etherport option for firmata.js repl
#!/usr/bin/env node
const firmata = require("./lib/firmata");
const Etherport = require("Etherport");
const repl = require("repl");
console.log('Enter USB Port or "etherport" and press enter:');
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.once("data", (chunk) => {
chunk = chunk.replace("\n", "");
@phoddie
phoddie / main.js
Created December 29, 2019 02:54
Generator and AsynGenerator prototypes - at preload and run time
import { link, test } from "test"
trace(link)
trace(test())
debugger
@phoddie
phoddie / app.js
Created December 6, 2019 17:24
Lightbulb example using Secure ECMAScript from talk given at Agoric meetup December 5, 2019 after TC39 San Francisco
/*
* Copyright (c) 2019 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
function traceBuffer(buffer) {
const bytes = new Uint8Array(buffer);
trace(`${bytes.length} byte ArrayBuffer\n`);
for (let i = 0; i < bytes.length; i += 16) {
let use = Math.min(bytes.length - i, 16);
let line = "";
for (let j = i; j < (i + use); j++) {
if (j !== i)
line += ", ";
line += bytes[j].toString(16).padStart(2, 0);
@phoddie
phoddie / hexdump.js
Last active March 25, 2020 05:16
hex dump an ArrayBuffer
function traceBuffer(buffer) {
const bytes = new Uint8Array(buffer);
trace(`${bytes.length} byte ArrayBuffer\n`);
for (let i = 0; i < bytes.length; i += 16) {
let line = [];
const end = i + Math.min(bytes.length - i, 16);
for (let j = i; j < end; j++)
line.push(bytes[j].toString(16).padStart(2, 0));
line = line.join(", ") + " ";
for (let j = i; j < end; j++) {
@phoddie
phoddie / bartleby.txt
Created July 3, 2020 15:06
httpserverresource
The Project Gutenberg EBook of Bartleby, The Scrivener, by Herman Melville
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net
Title: Bartleby, The Scrivener
A Story of Wall-Street
@phoddie
phoddie / main.js
Last active September 3, 2020 21:09
many web workers to exercise ESP32 CPU monitor in Moddable SDK
import Worker from "worker";
const workers = [];
export default function() {
for (let i = 0; i < 11; i++) {
const worker = new Worker("testworker", {
allocation: 11 * 1024,
stackCount: 64,
});