Skip to content

Instantly share code, notes, and snippets.

View cliffhall's full-sized avatar
💥
Technology pivot appearing onscreen now, captain.

Cliff Hall cliffhall

💥
Technology pivot appearing onscreen now, captain.
View GitHub Profile
@cliffhall
cliffhall / cordwood.js
Last active August 1, 2022 20:56
Extract substrings of predetermined a length, along with any remainder.
/**
* String.cordwood
*
* Add a String prototype method to split string into an array of
* substrings of a given length, along with any remainder.
*
* Example usage:
* let paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
* let stack = paragraph.cordwood(10)
* console.log(stack)
@cliffhall
cliffhall / a-render-and-transmit-test.md
Last active February 1, 2024 16:26
A Three.js / Socket.io / Node.js render and transmit test.

This example renders thirty frames of the Three.js 'your first scene' example and sends them to a Node.js microservice, which saves them to the filesystem.

test-render-client.html

  • Creates the scene, camera, renderer, and kicks off the render loop, which stops after 30 frames have been rendered.
  • As an optimization, it doesn't add the Three.js canvas to the browser DOM, rendering it offscreen, but reporting progress.
  • It extracts the data for each frame using canvas.toDataURL(), sending that to a web worker process for transmission.
  • When all frames are rendered, it sends a 'done' message to the worker.

test-render-worker.js

  • Sets up a queue for incoming frames to be sent to the server.