Skip to content

Instantly share code, notes, and snippets.

View aduth's full-sized avatar

Andrew Duthie aduth

View GitHub Profile
@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;
@aduth
aduth / input.js
Last active November 5, 2018 15:45
Publishing Small npm Libraries with Rollup
export default function() {}
@aduth
aduth / input.vue
Last active June 7, 2017 13:03
Vue Single-File Components Compilation
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
<ul>
<li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
<li><a href="https://gitter.im/vuejs/vue" target="_blank">Gitter Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
<br>
@aduth
aduth / shortener.user.js
Created June 20, 2017 01:20
GitHub Permalink Shortener
// ==UserScript==
// @name GitHub Permalink Shortener
// @namespace https://andrewduthie.com
// @version 0.1
// @description Shortens GitHub permalink ("Y" hotkey)
// @author Andrew Duthie
// @match https://github.com/*
// @grant MIT
// ==/UserScript==
@aduth
aduth / moize-minify.js
Created June 21, 2017 20:33
moize-minify Babel plugin
const stringsReplaced = [
'You must pass either a function or an object of options as the first parameter to moize.',
'You have not specified a promiseLibrary, and it appears that your browser does not support ' +
'native promises. You can either assign the library you are using to the global Promise object, or pass ' +
'the library in options via the "promiseLibrary" property.'
];
function getBinaryExpressionString( node ) {
return [ node.left, node.right ].reduce( ( result, operand ) => {
if ( operand.type === 'BinaryExpression' ) {
@aduth
aduth / index.js
Created July 20, 2017 01:11
requirebin sketch
var moize = require( 'moize' );
var memoized = moize((item) => {
return item;
});
try {
memoized.clear();
} catch ( error ) {
document.write( error.stack );
@aduth
aduth / stars-block.php
Last active February 15, 2022 04:13
Vue Custom Element Gutenberg Block
<?php
// NOTE: It would normally be recommended to split a block's JavaScript
// implementation to a separate file, but is authored here in a single
// file for convenience's sake.
//
// See: https://github.com/WordPress/gutenberg/pull/2791
/**
* Plugin Name: Stars Block
@aduth
aduth / demo-cpt.php
Created October 9, 2017 18:23
Demo WordPress Custom Post Type (CPT)
<?php
/**
* Plugin Name: Demo CPT
*/
add_action( 'init', function() {
register_post_type( 'book', [
'label' => 'Book',
'show_in_rest' => true,
@aduth
aduth / stars-block.js
Last active July 12, 2019 18:58 — forked from pento/stars-block.js
Gutenberg Stars Block
( function( blocks, element ) {
var el = element.createElement;
function Stars( { stars } ) {
return el( 'div', { key: 'stars' },
'★'.repeat( stars ),
( ( stars * 2 ) % 2 ) ? '½' : '' );
}
blocks.registerBlockType( 'stars/stars-block', {
@aduth
aduth / block-mobile-toolbar.jsx
Last active February 22, 2018 16:00
ifViewportSize
function BlockMobileToolbar( { uid, renderBlockMenu } ) {
return (
<div className="editor-block-list__block-mobile-toolbar">
<VisualEditorInserter />
<BlockMover uids={ [ uid ] } />
<BlockRemoveButton uids={ [ uid ] } small />
<BlockSettingsMenu uids={ [ uid ] } renderBlockMenu={ renderBlockMenu } />
</div>
);
}