Skip to content

Instantly share code, notes, and snippets.

View mzgoddard's full-sized avatar

Z Goddard mzgoddard

  • Bocoup
  • Boston, MA
View GitHub Profile
const a = ['a', 'b', 'c', 'd', 'e'];
const b = ['b', 'f', 'a', 'g', 'e'];
const table = {};
const d = [];
var isEqual = (a, b) => {
if (a.length === b.length) {
let isEqual = true;
for (let i = 0; isEqual && i < a.length; ++i) {
isEqual = a[i] === b[i];
<RAnimated name={name}
elements={{root: 'root'}}
// Build a animation state from the element
update={update.object({
x: element => element.getBoundingClientRect().left,
y: element => element.getBoundingClientRect().top,
width: element => element.getBoundingClientRect().width,
height: element => element.getBoundingClientRect().height,
opacity: () => 1,
})}
const Entities = require('html-entities').AllHtmlEntities;
const htmlEntities = new Entities();
class InlineCssHtmlWebpackPlugin {
apply(compiler) {
compiler.plugin('compilation', compilation => {
compilation.plugin('html-webpack-plugin-before-html-processing', (htmlPluginData, callback) => {
for (let filename of htmlPluginData.assets.css) {
const cssSrc = compilation.assets[filename];
@mzgoddard
mzgoddard / diff.js
Created April 13, 2017 20:22
Shallow object difference
// Create a difference of entries in an object when that object
// does not equal the new value shallowly.
//
// Example:
// a0 = {a: {b: {c: 3}, d: 4}}; a1 = {a: {b: a0.a.b, d: 5}};
// diff(a0, a1) = {a: {d: 5}};
const diff = (a, b) => {
let o;
if (a !== b) {
@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 / tessel-api-mockup.rs
Last active March 6, 2017 21:34
Mockup a Tessel API covering the same basic APIs as Tessel JS
//
// Examples
//
mod examples {
fn main() {
// Different ways to get a single pwm pin.
//
// These earlier ones are a bit wasteful as they also create the leds
@mzgoddard
mzgoddard / 00.script-async-attr-support-plugin.js
Created November 16, 2016 19:34
Plugin brainstorm to support async attribute use on script tags with webpack.
function ScriptAsyncAttrSupportPlugin() {}
module.exports = ScriptAsyncAttrSupportPlugin;
ScriptAsyncAttrSupportPlugin.prototype.apply = function(compiler) {
compiler.plugin('this-compilation', function(compilation) {
compilation.mainTemplate.plugin('bootstrap', function(source) {
return this.asString([
source,
'',
function DepthFirstPostPlugin() {}
module.exports = DepthFirstPostPlugin;
DepthFirstPostPlugin.prototype.apply = function(compiler) {
compiler.plugin('compilation', function(compilation) {
compilation.plugin('optimize-chunk-order', function(chunks) {
var checked = {};
function walk(chunk) {
var nextIndex = 0;
@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);
@mzgoddard
mzgoddard / webpack-bullets.md
Created August 11, 2016 18:17
High level steps webpack takes
  • create a compiler
  • apply options / configuration
    • apply plugins listed in options
    • add all other plugins based on options / configuration
    • example plugin: commonjsplugin
      • define dependency module factories
      • define dependency templates
      • plugin parser to create commonjs dependencies
  • run the compiler
  • create module factories