Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael "Z" Goddard mzgoddard

View GitHub Profile
View in-order-unique-union.js
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];
View ranimated-element.js
<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,
})}
View inline-css-html-webpack-plugin.js
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 Apr 13, 2017
Shallow object difference
View diff.js
// 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 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 / tessel-api-mockup.rs
Last active Mar 6, 2017
Mockup a Tessel API covering the same basic APIs as Tessel JS
View tessel-api-mockup.rs
//
// 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 Nov 16, 2016
Plugin brainstorm to support async attribute use on script tags with webpack.
View 00.script-async-attr-support-plugin.js
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,
'',
View depth-first-post-plugin.js
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 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);
@mzgoddard
mzgoddard / webpack-bullets.md
Created Aug 11, 2016
High level steps webpack takes
View webpack-bullets.md
  • 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
You can’t perform that action at this time.