Skip to content

Instantly share code, notes, and snippets.

Avatar

Frankie Jarrett fjarrett

View GitHub Profile
@fjarrett
fjarrett / async-array-walk.php
Last active Jan 26, 2021
Apply a user supplied function to every member of an array, in parallel. Similar to PHP's array_walk(), except the input array isn't passed by reference and the callbacks are ran asynchronously. The technique is highly portable and requires only PHP 5.4 and the PCNTL extension.
View async-array-walk.php
<?php
/**
* Apply a user supplied function to every member of an array, in parallel
*
* Similar to PHP's array_walk(), except the input array isn't passed by
* reference and the callbacks are ran asynchronously. The technique is highly
* portable and requires only PHP 5.4 and the PCNTL extension.
*
* The most obvious limitation is that we can't pass the input array by
@fjarrett
fjarrett / kernel-upgrade-how-to.md
Last active May 11, 2020
How to upgrade Linux kernel on CentOS 7
View kernel-upgrade-how-to.md

Confirm the current kernel version:

$ uname -snr
Linux 3.10.0-1062.18.1.el7.x86_64 x86_64

Add the ELRepo repository:

yum update -y
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
@fjarrett
fjarrett / atomic_deploy.sh
Created May 9, 2020
Just an idea for a "Capistrano style" deploy setup
View atomic_deploy.sh
#!/usr/bin/env bash
# BASE (required) - Releases are stored here.
# TARGET (required) - This will be a symlink to the current release.
# REPO (required) - The address to your Git repo.
# KEEP - How many latest releases to keep around (default is 10).
#
# Example:
#
# BASE=/var/www/foo/releases TARGET=/var/www/foo/public_html REPO=git@github.com:foo/bar.git ./atomic_deploy.sh 2b5d4a
@fjarrett
fjarrett / mu-plugin--wildcard-redirect-to-primary-host.php
Last active May 18, 2020
Wildcard redirect to primary host from alias domains
View mu-plugin--wildcard-redirect-to-primary-host.php
<?php
add_filter( 'init', function () {
if ( empty( $_SERVER['HTTP_AKAMAI_ORIGIN_HOP'] ) && empty( $_SERVER['HTTP_X_DSA_HOST'] ) && ! empty( $_SERVER['SERVER_NAME'] ) && 'origin-garage.godaddy.net' === $_SERVER['SERVER_NAME'] ) {
$path = ! empty( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '/garage';
wp_safe_redirect( 'https://www.godaddy.com' . $path, 301 );
@fjarrett
fjarrett / mu-plugin--block-robots-on-alias-domains.php
Last active May 18, 2020
Block robots from crawling alias domains
View mu-plugin--block-robots-on-alias-domains.php
<?php
add_filter( 'option_blog_public', function ( $blog_public ) {
if ( empty( $_SERVER['HTTP_AKAMAI_ORIGIN_HOP'] ) && empty( $_SERVER['HTTP_X_DSA_HOST'] ) ) {
$blog_public = false;
}
@fjarrett
fjarrett / webhook-wp-cli.php
Last active Mar 20, 2020
Run a WP-CLI command via an authorized HTTP POST webhook
View webhook-wp-cli.php
<?php
/**
* Run a WP-CLI command via an authorized HTTP POST webhook.
*
* curl -X POST https://mysite.com/webhook-wp-cli.php \
* -H 'Content-Type: application/json' \
* -H 'X-Authorization: Bearer MY_SUPER_SECRET_KEY_HERE' \
* -d '[ ["theme", "install"], ["https://downloads.wordpress.org/theme/go.zip"], ["force"], {"user": 1} ]'
*
@fjarrett
fjarrett / lock-down.php
Last active Oct 28, 2019
Simple must-use plugin to lock down WordPress and keep it up-to-date. Useful for canary sites.
View lock-down.php
<?php
/**
* Place this file in `wp-content/mu-plugins/lock-down.php` and it will be automatically loaded by WordPress.
*/
// Auto-update all the things.
add_filter( 'auto_update_core', '__return_true' );
add_filter( 'auto_update_plugin', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );
@fjarrett
fjarrett / wait-for-php-server-start.php
Created Aug 30, 2019
Use the Requests lib to wait for the built-in PHP server to start up
View wait-for-php-server-start.php
<?php
$process = new Process( sprintf( 'php -S localhost:8080 -t %s', __DIR__ ) );
$process->start();
$start = time();
// Wait for the server to start up (5 seconds max).
do {
try {
@fjarrett
fjarrett / .profile
Created Aug 10, 2017
Docker <--> Valet
View .profile
# Toggle localhost between Docker and Valet
quitapp () {
command osascript -e 'quit app "'$*'"' &
}
alias usevalet="quitapp Kitematic && quitapp Docker && valet restart && mysqld &>/dev/null &"
alias usedocker="open -a Docker && valet stop && mysql.server stop && open -a Kitematic"
@fjarrett
fjarrett / cdn-baseurl.php
Created Jul 20, 2017
Filter the media uploads baseurl to point to a CDN
View cdn-baseurl.php
<?php
// Turn ON: $ wp option update cdn_baseurl https://abc123.cloudfront.net/wp-content/uploads
// Turn OFF: $ wp option delete cdn_baseurl
$cdn_baseurl = get_option( 'cdn_baseurl' );
if ( ! $cdn_baseurl ) {
return;