Skip to content

Instantly share code, notes, and snippets.

View aduth's full-sized avatar

Andrew Duthie aduth

View GitHub Profile
@aduth
aduth / input.js
Last active November 5, 2018 15:45
Publishing Small npm Libraries with Rollup
export default function() {}
@aduth
aduth / simple-preact-slots.js
Created May 31, 2017 23:53
Simple Preact / React Slot & Fill Pattern
/**
* External dependencies
*/
import { createElement, Component } from 'preact';
const slots = {};
const fills = {};
let toUpdate = [],
nextUpdate;
// Action creators
function savePost( post ) {
return {
type: 'SAVE_POST',
post
};
}
function receivePost( post ) {

Quote:

<Element name="blockquote">
	<OneOrMore>
		<Element name="p">
			<Text as="value" />
		</Element>
	</OneOrMore>
	<Optional>
const { parse, registerBlock } = wp.blocks;
const { attr, html } = parse;
registerBlock( 'wp/image', {
schema: {
src: attr( 'img', 'src' ),
alt: attr( 'img', 'alt' ),
caption: html( 'figcaption' )
},
const parse, { query, text, attr } = wp.blocks.parse;
const quote = parse( '<blockquote><p>...</p><p>...</p><cite>Andrew</cite></blockquote>', {
text: query( 'p', text() ),
cite: text( 'cite' )
} );
// { text: [ "...", "..." ], cite: "Andrew" }
const image = parse( '<figure><img src="img.png" alt="Image"><figcaption>An Image</figcaption></figure>', {
@aduth
aduth / state-effects.js
Created December 15, 2016 14:46
redux effects middleware
// state/effects.js
/**
* Internal dependencies
*/
import post from './post/effects';
export default [
post
];
@aduth
aduth / find-warnings-to-upgrade.js
Last active November 1, 2016 15:19
Finds ESLint rules which are declared as warnings but for which there are no issues, to be safely upgraded to error
/* eslint-disable no-console */
/**
* External dependencies
*/
const execSync = require( 'child_process' ).execSync;
const reduce = require( 'lodash/reduce' );
/**
* Internal dependencies
@aduth
aduth / gforms_placeholders.php
Created October 25, 2013 20:13
Gravity Forms placeholders using a combination of default value and "gforms-placeholder" class
function enable_gforms_placeholders($content, $field, $value, $lead_id, $form_id) {
if (strpos($field['cssClass'], 'gforms-placeholder') !== false) {
switch ($field['type']) {
case 'text':
case 'phone':
case 'website':
case 'number':
case 'name':
case 'address':
case 'email':
@aduth
aduth / gist:5543247
Created May 8, 2013 20:08
Convert CSS3 transition duration string to milliseconds
var transitionDurationToMilliseconds = function(duration) {
var pieces = duration.match(/^([\d\.]+)(\w+)$/),
time, unit, multiplier;
if (pieces.length <= 1) {
return duration;
}
time = pieces[1];
unit = pieces[2];