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 / a-simple-socket-io-test.md
Last active November 5, 2016 21:27
A simple Socket.io test with client and server (Node.js) parts.
@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.

This demo builds on previous gists in this series to render an audio-modulated WebGL animation, and output a 48 FPS, 1080p, HD video utilizing:

  • HTML5's Web Audio API for analysing an audio file.
  • HTML5's Web Worker API for offloading communications between the web page and the server to separate thread.
  • Socket.io for sending messages (including image and audio files) between client and server.
  • Node.js for the server process for storing generated images and uploaded audio and creating the final video.
  • FFMpeg for the actual video creation.
  • Fluent-ffmpeg for making the configuration and execution of FFMpeg commands easy peasy.
  • @ffmpeg-installer/ffmpeg for installing the correct version of FFMpeg for the hardware this demo runs on.
  • mkdirp for creating the folder path for each client's data, including any missing nodes in the path.
@cliffhall
cliffhall / nuke-firebase-db-and-users-referenced-therein.js
Last active September 24, 2018 22:15
Nuke a Firebase Database and All User Accounts Referenced Therein
// NOTE: Accounts that are not represented in your /users node will not be deleted!
// BLOG: There are other approaches, see: http://cliffordhall.com/2017/04/nuke-firebase-db-and-all-users/
"use strict";
// Get credentials and initialize firebase app
console.log("With the power vested in the admin user, lay waste the database and all its users!");
let admin = require("firebase-admin");
let serviceAccount = require([__dirname, "service-account-key.json"].join('/'));
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
@cliffhall
cliffhall / index.js
Last active November 29, 2018 11:53
Using Firebase Cloud Functions to Manage a Compound Key Index
/**
* Function: indexArtist
*
* Triggered by writes to: /artists/:id
* Responds by writing to: /indexes/artist_by_genre (once for each Genre the Artist has chosen)
*
* If there was a previous value, all associated index entries are removed first.
* So, if the artist display name has changed or the genre list has changed,
* the index will be properly synchronized.
*
@cliffhall
cliffhall / a-simple-sinewav3-plugin-example.md
Last active April 17, 2018 16:03
Sinewav3 Plugin Example 'Tentacles'

The Sinewav3 Plugin example 'Sparks Fly' creates a particle system simulating sparks which dim as they age, while moving in a realistic fashion.

A number of settings are exposed for the particle system emitter and its movement as well as the protoypical spark particle and its movement. The code demonstrates the use of audio modulation and easing.

Learn more about this plugin here: https://medium.com/sinewav3/make-sparks-fly-c48e94219d4f

@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 / FundsHandlerRegistry.sol
Last active March 9, 2022 06:28
A factory/registry for deploying cheap, minimal clones of royalty funds handler logic and retrieving those clones by token address and id
pragma solidity 0.8.4;
import "@openzeppelin/contracts/proxy/Clones.sol";
import "./IFundsHandler.sol"; // Multiple funds receiver/splitter logic implementations can exist
contract FundsHandlerRegistry {
// Available IFundsHandler implementations
mapping(string => address) handlers;
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.0;
/**
* @notice KeyToken is the Fismo Lab ERC-20, and we only check for a balance
*/
interface KeyToken {
function balanceOf(address account) external view returns (uint256);
}