Skip to content

Instantly share code, notes, and snippets.

View aduth's full-sized avatar

Andrew Duthie aduth

View GitHub Profile
registerBlockType( 'core/colorable', {
abstract: true,
attributes: {
color: {
type: 'string',
},
},
edit: () => (
@aduth
aduth / index.html
Created December 30, 2018 21:19
Pop vs. Splice negative (http://jsbench.github.io/#d4e1fe19291d325ae4fdc4e8cc609d1b) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Pop vs. Splice negative</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Number Cast</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@aduth
aduth / index.html
Created December 13, 2018 17:06
Gutenberg - Optimize runSelector (http://jsbench.github.io/#479cdbd5b639b3eff88dede976893a25) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Gutenberg - Optimize runSelector</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@aduth
aduth / with-caching.txt
Created November 6, 2018 16:20
@tannin/sprintf vs. sprintf-js
sprintf-js: hello %s! x 3,492,089 ops/sec ±0.35% (93 runs sampled)
@tannin/sprintf: hello %s! x 1,737,159 ops/sec ±0.38% (87 runs sampled)
@aduth
aduth / input.js
Last active November 5, 2018 15:45
Publishing Small npm Libraries with Rollup
export default function() {}
@aduth
aduth / blocks.js
Created October 2, 2018 18:08
Data Module - withSelect & withDispatch
( function( blocks, element, data, components, compose ) {
var el = element.createElement;
blocks.registerBlockType( 'my-demo/demo-block-select', {
title: 'Demo Block (Select)',
icon: 'format-aside',
category: 'common',
@aduth
aduth / gitco.sh
Created June 11, 2018 13:12
Git Checkout GitHub Remote Branch
#!/bin/bash
# https://stackoverflow.com/a/26843249/995445
IFS=':' read -ra parts <<< "$1"
if [ ${#parts[@]} == 1 ]; then
branch=${parts[0]}
else
remote=${parts[0]}
branch=${parts[1]}
fi
@aduth
aduth / components|async-component|index.js
Created June 8, 2018 14:11
WordPress Async Components
class AsyncComponent extends Component {
constructor() {
super( ...arguments );
this.state = {
component: null,
};
}
componentWillMount() {
/**
* Higher-order component used to inject state-derived props using registered
* selectors.
*
* @param {Function} mapStateToProps Function called on every state change,
* expected to return object of props to
* merge with the component's own props.
*
* @return {Component} Enhanced component with merged state data props.
*/