Skip to content

Instantly share code, notes, and snippets.

View mzgoddard's full-sized avatar

Z Goddard mzgoddard

  • Bocoup
  • Boston, MA
View GitHub Profile
@mzgoddard
mzgoddard / example.toml
Last active July 24, 2020 16:36
TOML Grammers
# A TOML example. Unlike JSON it supports comments.
[player]
particles = [
[ 0.0, -5.0 ],
[ 4.330127018922194, -2.4999999999999996 ],
[ -4.330127018922194, -2.4999999999999996 ]
]
# Unlike YAML, there is only one way to write arrays.
# There is only one way to write tables too.
# This reduces implementation complexity for a TOML parser.
@mzgoddard
mzgoddard / fetch-response-arraybuffer-implementation.js
Created July 16, 2019 16:33
Example manual implementation of fetch().then(response => response.arrayBuffer())
// Body mixin arrayBuffer helper.
return response.arrayBuffer();
// Example implementation of arrayBuffer().
const reader = response.body.getReader();
return new Promise((resolve, reject) => {
const chunks = [];
const step = function () {
reader.read().then(({done, value}) => {
if (done) {
@mzgoddard
mzgoddard / index.html
Created July 10, 2019 17:57
Time to open an electron window.
<div class="times"></div>
<script>
const now = Date.now();
setTimeout(function () {
const div = document.querySelector('.times');
const search = location.search.substring(1).split('&').map(pair => pair.split('=')).reduce((carry, [key, value]) => {
carry[key] = Number(value);
return carry;
}, {});
@mzgoddard
mzgoddard / awebp.sh
Created August 20, 2014 16:44
Turn a movie into an animated webp.
#!/bin/zsh
movieInput=$1
tmpFolder=$2
outName=$3
mkdir -p $tmpFolder
ffmpeg -i $movieInput $tmpFolder/%03d.png
for i in `ls $tmpFolder`; do
j=`echo $i | sed s/\.png/.webp/`
@mzgoddard
mzgoddard / tessel-spi-neopixels.js
Created January 16, 2017 19:54
Animate a 12 component adafruit neopixel ring with SPI
// Import the interface to Tessel hardware
var tessel = require('tessel');
var port = tessel.port.A;
var spi = new port.SPI({
clockSpeed: 3.2*1000*1000, // 3.2MHz
cpol: 0, // Polarity - optional
cpha: 0, // Clock phase - optional
chipSelect: port.pin[7] // Chip select - optional
@mzgoddard
mzgoddard / build-step-time-webpack-plugin.js
Last active June 28, 2018 22:08
Little webpack plugin for digging out some time info
// Drop this in as the first plugin in a webpack config
{
apply: function(compiler) {
var start;
compiler.plugin(['watch-run', 'run'], function(compiler, cb) {
start = Date.now();
cb();
});
compiler.plugin('make', function(compilation, cb) {
console.log('pre-make', Date.now() - start);

cacache is far too slow as a read and write cache to disk solution for hard-source.

On one test project on an older 13" MBP:

@latest #cacache
initial build 28s 38s
iterative build 4.7s 11s

Instead of replacing, cacache will be an optional serializer like leveldb. Replacing append-serializer will fall to a new version of its idea. Instead of so finely trying to maximize use of append mode files, write out a log file once, with the meta info at the beginning and in a separate file additionally. Reading all the files in reverse builds up the prior state.

@mzgoddard
mzgoddard / scratch-webpack-4-research.md
Created April 25, 2018 21:55
Scratch webpack time and size deltas bumping to webpack 4

webpack version, loaders and plugins by repo

scratch-vm webpack@3 babel-loader buffer-loader@0.0.1 copy-webpack-plugin expose-loader file-loader script-loader

Current Problems & Scenarios

Users get fast webpack builds on large code bases by running continuous processes that watch the file system with webpack-dev-server or webpack's watch option. Starting those continuous processes can take a lot of time to build all the modules for the code base anew to fill the memory cache webpack has to make rebuilds fast. Some webpack uses remove the benefit from running a continuous process like running tests on a Continuous Integration instance that will be stopped after it runs, or making a production build for staging or release which is needed less frequently than development builds. The production build will just use more resources while the development build completes faster from not using optimization plugins.

Community solutions and workarounds help remedy this with cache-loader, DllReferencePlugin, auto-dll-plugin, thread-loader, happypack, and hard-source-webpack-plugin. Many workarounds also include option tweaks that trade small loses in file size or feature p

// Copyright 2018 Michael "Z" Goddard
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in