Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael "Z" Goddard mzgoddard

View GitHub Profile
@mzgoddard
mzgoddard / example.toml
Last active Jul 24, 2020
TOML Grammers
View example.toml
# 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 Jul 16, 2019
Example manual implementation of fetch().then(response => response.arrayBuffer())
View fetch-response-arraybuffer-implementation.js
// 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 Jul 10, 2019
Time to open an electron window.
View index.html
<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 Aug 20, 2014
Turn a movie into an animated webp.
View awebp.sh
#!/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 Jan 16, 2017
Animate a 12 component adafruit neopixel ring with SPI
View tessel-spi-neopixels.js
// 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 Jun 28, 2018
Little webpack plugin for digging out some time info
View build-step-time-webpack-plugin.js
// 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);
View append-serializer-2.md

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 Apr 25, 2018
Scratch webpack time and size deltas bumping to webpack 4
View scratch-webpack-4-research.md

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

View webpack-cache-spec.md

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

View datapacktoy.js
// 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
You can’t perform that action at this time.