Skip to content

Instantly share code, notes, and snippets.

View mcaskill's full-sized avatar
🥃

Chauncey McAskill mcaskill

🥃
View GitHub Profile
@mcaskill
mcaskill / sphp.sh
Last active September 22, 2022 02:33 — forked from rhukster/sphp.sh
Easy Brew PHP version switching
#!/bin/bash
# Creator: Phil Cook
# Modified: Andy Miller (2020-11-27)
# Modified: Chauncey McAskill (2022-09-21)
osx_major_version=$(sw_vers -productVersion | cut -d. -f1)
osx_minor_version=$(sw_vers -productVersion | cut -d. -f2)
osx_patch_version=$(sw_vers -productVersion | cut -d. -f3)
osx_patch_version=${osx_patch_version:-0}
osx_version=$((${osx_major_version} * 10000 + ${osx_minor_version} * 100 + ${osx_patch_version}))
@mcaskill
mcaskill / Function.Strip-HTML.php
Last active January 4, 2022 10:38
PHP : Strip HTML and PHP tags from a string.
<?php
if (!function_exists('strip_html')) {
/**
* Strip HTML and PHP tags from a string.
*
* @param string $str The input string.
* @return string Returns the stripped string.
*/
function strip_html($str)
@mcaskill
mcaskill / composer.sh
Last active July 28, 2021 13:59
Better safe than sorry. A shell function wrapper for Composer to check for local changes and create back-ups before executing operations that may overwrite data.
#
# Alias of `composer` command that, if Composer's installed.json is present, checks
# for local changes in dependencies and backs-up the composer.json, composer.lock,
# and vendor directory before executing install, reinstall, or update commands.
#
# Useful if you often need to modify the code of your dependencies and they are
# installed from source.
#
# Version: 1.1.0
# License: MIT
@mcaskill
mcaskill / wp-leadingslash.php
Created April 17, 2015 15:38
WordPress \ Formatting : Prepends a leading slash and removes leading forward slashes and backslashes if they exist.
<?php
/**
* Prepends a leading slash.
*
* Will remove leading forward and backslashes if it exists already before adding
* a leading forward slash. This prevents double slashing a string or path.
*
* The primary use of this is for paths and thus should be used for paths. It is
* not restricted to paths and offers no specific path support.
@mcaskill
mcaskill / wp-nav_trail
Created November 28, 2014 06:59
WordPress : Displays a location breadcrumb trail using WordPress navigation menus.
<?php
/**
* Displays a location breadcrumb trail.
*
* Uses WordPress nav menu items and theme locations to build
* a breadcrumb trail. Overall, this template functon replicates
* most of the procedures found in `wp_nav_menu()`.
*
* @param array $args {
@mcaskill
mcaskill / check-multiple-inputs.js
Last active September 19, 2020 16:43
JS : Toggle a range of checkboxes using the shift-key
(function () {
const table = document.getElementById('my-table');
let lastInput = null;
table.addEventListener('click', function (event) {
const currInput = event.target;
if (currInput.type !== 'checkbox') {
return;
}
@mcaskill
mcaskill / persist-checked-inputs.js
Created September 19, 2020 15:06
JS : Persist checked inputs in web storage
(function () {
const table = document.getElementById('my-table');
const store = window.localStorage;
table.querySelectorAll('[type="checkbox"]').forEach(function (input) {
input.checked = !!store.getItem(`${input.name}_${input.value}`);
});
table.addEventListener('change', function (event) {
let input = event.target;
@mcaskill
mcaskill / Function.Array-Insert.php
Last active April 13, 2020 13:11
PHP : Insert elements from a passed array into the first array
<?php
if (!function_exists('array_insert')) {
/**
* Insert an array into another array before/after a certain key
*
* Merge the elements of the $array array after, or before, the designated $key from the $input array.
* It returns the resulting array.
*
* @param array $input The input array.
@mcaskill
mcaskill / Function.Is-Var-Empty.php
Last active April 13, 2020 13:10
PHP : Determine whether a variable or object is empty.
<?php
if (!function_exists('is_var_empty')) {
/**
* Determine whether a variable is empty.
*
* Alternative to {@see empty()} which will resolve stringable and arrayable objects.
*
* @param mixed $var The value to be checked.
* @return boolean Returns FALSE if var exists and has a non-empty value. Otherwise returns TRUE.
@mcaskill
mcaskill / Function.Get-Var-Type.php
Last active April 13, 2020 13:07
PHP : Get the type, resource name, or class name of a variable.
<?php
if (!function_exists('get_var_type')) {
/**
* Get the type, resource name, or class name of a variable.
*
* Returns the type (name if an object or resource) of the PHP variable $var.
*
* @link http://php.net/manual/en/function.gettype.php#104224
* @param mixed $var The variable being type checked.