Skip to content

Instantly share code, notes, and snippets.

View mcaskill's full-sized avatar
🥃

Chauncey McAskill mcaskill

🥃
View GitHub Profile
@mcaskill
mcaskill / charcoal-collection-loader-model-caching.php
Created July 3, 2019 14:30
Charcoal : How to cache object data from a `CollectionLoader` into a `ModelLoader` cache namespace.
<?php
use Pimple\Container;
use Charcoal\Model\ModelInterface;
use Charcoal\Model\CollectionInterface;
use App\Post;
$container = new Container();
$container['cache'] = function (Container $container) {
@mcaskill
mcaskill / Function.Blade-Props.php
Created April 28, 2019 19:54
Blade : Keep partials reusable with two presenter-style functions.
<?php
/**
* Convert array to an object recursively, a new instances of the stdClass.
*
* @param array $props The array to convert into an object.
* @return object
*/
function props(array $props) : object
{
@mcaskill
mcaskill / wp-without-hooks.php
Last active January 18, 2019 17:09 — forked from westonruter/01-common-example.php
WordPress \ Hooks : Temporarily disable hooks while executing a given callback.
<?php
/**
* Call the callback with one or all handlers disabled for the given action or filter.
*
* Temporarily disables the specified hook, or all hooks, from a specified filter or action
* before calling $callback.
*
* @link https://gist.github.com/westonruter/6647252
*
@mcaskill
mcaskill / wp-add-hooks.php
Created January 18, 2019 17:05
WordPress \ Hooks : Hook a function or method to an array of actions or filters.
<?php
/**
* Hook a function or method to an array of actions.
*
* @param string[] $tags Array of names of filters to hook the $function callback to.
* @param callable $function_to_add The callback to be run when the filter is applied.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
@mcaskill
mcaskill / Function.Array-Chunk-By.php
Last active October 25, 2023 17:38
PHP : Splits an array into chunks using a callback function.
<?php
if (!function_exists('array_chunk_by')) {
/**
* Splits an array into chunks using a callback function.
*
* Chunks an array into arrays by iteratively applying the $callback function
* to the elements of the $array.
*
* @see https://rlaanemets.com/post/show/group-array-by-adjacent-elements-in-javascript
@mcaskill
mcaskill / elogram.php
Created June 26, 2017 14:22
Elogram Quickstart
<?php
use Larabros\Elogram\Client;
header('Content-Type: application/json;charset=utf-8');
/** Register the Composer autoloader */
require dirname(__DIR__) . '/vendor/autoload.php';
$clientId = '';
@mcaskill
mcaskill / String.prototype.explode.js
Created April 25, 2017 02:43
JS : Split a string by string
if (!String.prototype.explode) {
/**
* Split a string by string
*
* Splits a String object into an array of substrings, each of which is formed
* by splitting it on boundaries formed by the string delimiter.
*
* @link http://locutus.io/php/explode/ Created by Kevin van Zonneveld (http://kvz.io)
* @example
* 'Kevin van Zonneveld'.explode(' ') // [ 'Kevin', 'van', 'Zonneveld' ]
@mcaskill
mcaskill / Function.Is-Blank.php
Last active September 10, 2018 01:58
PHP : Determine whether a variable has a non-empty value.
<?php
if (!function_exists('is_blank')) {
/**
* Determine whether a variable has a non-empty value.
*
* Alternative to {@see empty()} that accepts non-empty values:
* - _0_ (0 as an integer)
* - _0.0_ (0 as a float)
* - _"0"_ (0 as a string)
@mcaskill
mcaskill / charcoal-slim-redirections.php
Created December 8, 2016 14:38
Charcoal : Route Aliases & Redirections for Slim
<?php
/**
* Route Aliases & Redirections
*
* @global App $app The Charcoal application.
* @global Container $container The DIC.
* @todo Add support for request method lookup, not just response method.
*/
@mcaskill
mcaskill / Function.Compose-Sequence.php
Created November 11, 2016 18:15
PHP : Function composition — 'a(b(c(x)))' or 'c(b(a(x)))'
<?php
/**
* Compose the given functions into a new one (`a(b(c(x)))`).
*
* Similar to {@see sequence()}, except the function list is executed in reverse —
* the last function is executed first.
*
* ```
* compose(a, b, c) => a(b(c(x)))