Skip to content

Instantly share code, notes, and snippets.


Matthew Stokeley matthewstokeley

Block or report user

Report or block matthewstokeley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:ee755219bc76db05f8e87a4625e6b4bc
* @link
if (called)
called = true;
if (err)
return cb(err)
git filter-branch notes

	- Rewrite git revision history
		- Applicable to `rev-list` branches
		- Only rewritepositive refs
		- Recommitted without any changes, unless filter is specified
		- Honors `.git/info/grafts` and refs in `refs/replace/`
		- Original refs written in `refs/original/`
View find-method.php
function _find( $needle, $haystack, $is_key = false ) {
if ( $is_key === true ) :
return function( Callable $comparator ) use ( $needle ) {
return call_user_func( $comparator, $needle );
matthewstokeley / environment-specific-event-propagation.php
Last active Nov 21, 2019
environment-specific event-propagation would you rather array, call, invoke
View environment-specific-event-propagation.php
// implementation detail
define( 'IS_LOCAL_ENV', true );
function call_env_specific_event_prop(
Callable $method,
) {
if ( ! IS_LOCAL_ENV ) {
matthewstokeley / lazy-load.html
Last active Nov 19, 2019
native image lazy loading with fall back
View lazy-load.html
<!-- -->
<img src="" srcset="" loading="lazy" data-lazy-load="true" alt="" />
if ( HTMLImageElement.prototype.loading === undefined ) {
// load lazy loading plugin
matthewstokeley /
Last active Nov 19, 2019
Example PWA manifest

<link rel="manifest" href="/manifest.json">

From the google documentation:

  "short_name": "Maps",
  "name": "Google Maps",
  "icons": [
      "src": "/images/icons-192.png",

Lexical scope

Javascript does not have a mechanism to preserve the global namespace, which can lead to namespace collisions and other errors. Foundation uses a one-line initialization script, var foundation = {}, to create an object that can function as a namespace. In Javascript, when an object is declared, an environment record or scope is also created - functions and variables located within the same environment record have access to each other. Objects and functions contain their own environment record. try catch blocks and conditionals do not.

The IIFE was a popular construct used in the development of jQuery and documented in Addy Osmani's JS Design Patterns as the revealing module pattern to help avoid namespace and scope collisions by wrapping a function with an immediately-invoked function - the wrapper is invoked on runtime and functions and variables are declared within the IIFE's scope rather than the global scope.

View template-caching-handler.js
* @version 0.0.2
( function( $ ) {
const KEY = 'template-name'
const HTML_KEY = 'html'
const CONTAINER = '.container'
matthewstokeley / hasAttr.js
Last active Nov 13, 2019
does an element have an attribute
View hasAttr.js
// has
const hasAttr = ( _el, attr ) => {
if ( ! _el.children[0] ) {
return false;
if ( _el.nodeType !== 1) {
return false;
matthewstokeley /
Last active Nov 9, 2019
a comparison of different ways to handle asynchronous responses

note: await is not available in ie

in this xhr library, which offers a simple xhr api and a request api using html data attributes, I used a pubsub pattern to listen for events. Until IE support is offered, this is a nice and agnostic client-side approach without needing polyfills or complicated build processes.

var events = {
    events: [],
    emit: function(event, response) { ... },
    addEventListener: function(event, fn) { ... }
You can’t perform that action at this time.