Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Matthew Stokeley matthewstokeley

🎯
Focusing
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 https://github.com/nodejs/node/blob/master/lib/_http_agent.js
*/
if (called)
return;
called = true;
if (err)
return cb(err)
@matthewstokeley
matthewstokeley / preparation.js
Last active Dec 10, 2019
What if javascript had printf - pdo-style api
View preparation.js
// @todo wishlist - isomorphic node-style error handling
const traverse = function() {}
const iterate = (arr) => {
const arr = arr;
const pos = 0;
const next = () => {}
View filter-branch-notes.md
git filter-branch notes

Summary
	- 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
<?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
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
<?php
// implementation detail
define( 'IS_LOCAL_ENV', true );
function call_env_specific_event_prop(
Callable $method,
$arg
) {
if ( ! IS_LOCAL_ENV ) {
@matthewstokeley
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="" />
<script>
if ( HTMLImageElement.prototype.loading === undefined ) {
// load lazy loading plugin
}
</script>
@matthewstokeley
matthewstokeley / manifest.json.md
Last active Nov 19, 2019
Example PWA manifest
View manifest.json.md

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

From the google documentation:

{
  "short_name": "Maps",
  "name": "Google Maps",
  "icons": [
    {
      "src": "/images/icons-192.png",
View annotated-iife-scope.md

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
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;
You can’t perform that action at this time.