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 / 01.node-object-hash.sort.js
Created December 23, 2017 16:53
string-replace-webpack-plugin
const objectHash = require('node-object-hash');
console.log(objectHash({sort: false}).sort(module.exports));
// Different config content between build 1 and 2
`string-replace-webpack-plugin/loader.js?id=ay3quvgnd7k`
`string-replace-webpack-plugin/loader.js?id=z5o2gtqy17d`
// Build 1 hashed config content
`{context:/Users/zen/Code/webpack/hard-source-string-replace,entry:./index.js,ou
  • read
    • read table
    • each log
      • open
      • check block status
      • add block to file
      • if file complete emit it
  • batch put/del
    • read table
  • open current log
@mzgoddard
mzgoddard / babel-boxart-plugin-rudimentary.js
Last active November 5, 2017 17:55
Rudimentary Boxart plugin transforming bablyon tree to flatten functions
// function gen() {
// return (function(fn) {
// const f = function(t, state, begin, end) {
// var b = {b: 1};
// var c = {f2: function(t) {return t;}};
// state.left = c.f2(b.b, state, begin, end) * 2;
// return state;
// };
// return f;
// })((function(fn) {
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="BoxArt animation with MutationObserver">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.column {
display: inline-block;
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-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,
'',