Skip to content

Instantly share code, notes, and snippets.

View aduth's full-sized avatar

Andrew Duthie aduth

View GitHub Profile
<!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 / 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.
*/
@aduth
aduth / changed-props.js
Last active April 26, 2018 17:51
componentDidUpdate Changed Props
class MyComponent extends React.Component {
// ...
componentDidUpdate( prevProps ) {
for ( const key of Object.keys( this.props ) ) {
if ( this.props[ key ] !== prevProps[ key ] ) {
console.log(
key,
`(Before: ${ prevProps[ key ] })`,
`(After: ${ this.props[ key ] })`
@aduth
aduth / gitremoterm.sh
Created March 8, 2018 03:03
Git remote all remotes except origin
#!/bin/bash
git remote -v | grep "(fetch)" | sed -e 's#[[:blank:]].*##g' | grep -v "origin" | xargs -n 1 git remote rm
@aduth
aduth / gitco.sh
Created March 8, 2018 03:03
Checkout from GitHub remote via `user:branch` syntax
#!/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