Skip to content

Instantly share code, notes, and snippets.

View bericp1's full-sized avatar

Brandon Phillips bericp1

View GitHub Profile
@bericp1
bericp1 / AlternativeFileReplacerPlugin.js
Last active March 17, 2021 16:04
A webpack plugin that replaces a file with an alternate version alongside it.
const path = require('path');
const escapeStringRegExp = require('escape-string-regexp');
const _debug = require('debug');
const PLUGIN_NAME = 'AlternativeFileReplacerPlugin';
const debug = _debug(PLUGIN_NAME);
/**
* Create an "isFileAccessible" function for an `fs` interface that has a `stat` function.
@bericp1
bericp1 / debug-rewrite-rules.php
Created October 9, 2019 16:36
WP Template and Rewrite Rule Debug – just drop in `mu-plugins/`
<?php
/**
* Adapted from
*
* @param string $where
*
* @return bool
*/
function car_debug_rewrite_rules()
@bericp1
bericp1 / alert.js
Created September 20, 2019 17:13
An alert module
import { flatten } from 'ramda';
/**
* The default alert message type.
*
* @constant
* @type {string}
*/
export const DEFAULT_ALERT_TYPE = 'info';
@bericp1
bericp1 / output.txt
Created August 13, 2019 23:23
Output of `yarn run react-native-schemes-manager fix-libraries` on RN 0.60.5
yarn run v1.16.0
$ PROJECT_PATH_OMITTED/node_modules/.bin/react-native-schemes-manager fix-libraries
✔ [fix-libraries]: Debug -> DevDebug created in node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj
✔ [fix-libraries]: Debug -> StagingDebug created in node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj
✔ [fix-libraries]: Release -> DevRelease created in node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj
✔ [fix-libraries]: Release -> StagingRelease created in node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj
✔ [fix-libraries]: Debug -> DevDebug created in node_modules/react-native/Libraries/ART/ART.xcodeproj
✔ [fix-libraries]: Debug -> StagingDebug created in node_modules/react-native/Libraries/ART/ART.xcodeproj
✔ [fix-libraries]: Release -> DevRelease created in node_modules/react-native/Libraries/ART/ART.xcodeproj
✔ [fix-libraries]: Release -> StagingRelease created in node_modules/react-native/Librari
@bericp1
bericp1 / createTimer.js
Created July 19, 2019 22:57
Creates a high resolution timer. Call with a name to start. Call with a new name to "lap". Call with no arguments to stop.
function createTimer (log) {
let prev = null;
function hrtimeDurationToMs([durS, durUs]) {
return ((durS * 1000) + (durUs / 1000000)).toFixed(4);
}
return (name = null) => {
if (prev) {
const dur = hrtimeDurationToMs(process.hrtime(prev[1]));
log(`end ${prev[0]}, took ${dur}ms`, { name: prev[0], hrtime: prev[1], dur });
}
@bericp1
bericp1 / tbit.sh
Created January 22, 2019 20:48
Bash-wrapped AppleScript to toggle the "built-in trackpad disabled" accessibility setting.
# Built-in Trackpad toggle script
# https://github.com/Ryderpro/Apple-Scripts
osascript <<'END'
tell application "System Preferences"
quit
delay 1
end tell
tell application "System Preferences"
@bericp1
bericp1 / CurrentUserAwareModel.php
Created January 9, 2019 02:34
A Laravel model abstraction for models whose relationships or dynamic attributes should be current-user-aware. A little better than using global scope (i.e. `\Auth::user();`) but not much better.
<?php
namespace App\Support;
use App\User;
use Illuminate\Database\Eloquent\Model;
abstract class CurrentUserAwareModel extends Model
{
/**
@bericp1
bericp1 / custom-search-acf-wordpress.php
Created October 10, 2018 17:07 — forked from charleslouis/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@bericp1
bericp1 / database.php
Created August 28, 2018 22:15
Per-cluster Redis Config For Laravel
<?php
return [
// ...
'redis' => [
'options' => [
// Options can be specified here (with the lowest precedence).
],
let x = 0;
async function test() {
x += await 2;
console.log(x);
}
test();
x += 1;
console.log(x);