Skip to content

Instantly share code, notes, and snippets.

View timwhitlock's full-sized avatar

Tim Whitlock timwhitlock

View GitHub Profile
@timwhitlock
timwhitlock / convert_array_access_braces.php
Last active September 30, 2020 10:55 — forked from theodorejb/convert_array_access_braces.php
Migrate deprecated curly brace array access syntax to bracket syntax. Requires PHP 7.4.
<?php
error_reporting(E_ALL);
$opts = getopt('f:d:rb:', ['ext:', 'php:', 'diff::']);
if ((int)isset($opts['d']) + (int)isset($opts['f']) !== 1) {
$self = basename(__FILE__);
echo <<<EOF
Usage:
php $self -f<php_script> [-b] [--php <path_to_php>] [ --diff [<file>]]
@timwhitlock
timwhitlock / client.php
Last active November 7, 2019 15:09
Simple 0MQ client/server pattern
<?php
// Client: Pings server, gets reply. Exits.
$zmq = new ZMQContext;
$sock = new ZMQSocket( $zmq, ZMQ::SOCKET_REQ );
$sock->connect('tcp://localhost:5555');
echo "Pinging..\n";
$sock->send('Ping');
@timwhitlock
timwhitlock / rotate-backups.sh
Last active May 16, 2019 15:43
Disk backup rotation script
#!/bin/bash
# Rotates disk image backups inside working directory
# Maintains a rolling window of 4 hourly snapshots (uncompressed)
# Plus 7xdays and 6xmonths of older compressed archives
# config
HOURS=4
DAYS=7
MONTHS=6
@timwhitlock
timwhitlock / mongo-insert-bench.php
Created March 21, 2019 20:35
bulkWrite benchmarks for different write concerns
<?php
function runTest( MongoDB\Driver\WriteConcern $writeConcern ){
$bulk = new MongoDB\Driver\BulkWrite(['ordered'=>false]);
for( $i = 0; $i < 10000; $i++ ){
$bulk->insert( [
'time' => new MongoDB\BSON\UTCDateTime,
] );
}
@timwhitlock
timwhitlock / loco-translate-webhook.php
Created November 15, 2018 16:34
Loco Translate Webhook example
<?php
/*
Plugin Name: Loco Webhook
Description: Monitors changes to PO files during save operations
Author: Tim Whitlock
*/
class LocoWebhook {
private $path;
@timwhitlock
timwhitlock / valencian.php
Created February 28, 2018 13:42
Forces Loco Translate to display Catalan as Valencian without changing "ca" tag
<?php
/*
Plugin Name: Valencia variant
Description: Makes "ca" locale appear like "ca-valencia" in Loco Translate
Author: Tim Whitlock
Version: 1.0.0
*/
// Only running for admin screens
@timwhitlock
timwhitlock / buddypress.pot
Last active February 10, 2018 15:31
POT template for BuddyPress 2.9.3
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: BuddyPress 2.9.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-10 15:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
@timwhitlock
timwhitlock / preload-ssh2.php
Created May 6, 2017 10:35
Ensures custom SSH2 class is loaded before autoloader is triggered by class_exists
<?php
/*
Plugin Name: Preload SSH class
Plugin URI: https://wordpress.org/support/topic/conflict-with-ssh-sftp-updater-support-ssh2-fs_method/
Description: Ensures custom SSH2 class is loaded before autoloader is triggered by class_exists
Author: Tim Whitlock
*/
function filter_filesystem_method( $method = '' ){
if( 'ssh2' === $method && ! class_exists('WP_Filesystem_SSH2',false) ){
@timwhitlock
timwhitlock / diable-auto-translation-updates.php
Last active April 11, 2024 10:44
Prevents WordPress from automatically updating translation files in the global languages directory
<?php
/*
Plugin Name: Disable auto translation updates
Description: Prevents WordPress from automatically updating translation files in the global languages directory.
Author: Tim Whitlock
Version: 1.0
*/
/**
@timwhitlock
timwhitlock / loco-loader.php
Last active October 17, 2023 17:28
Standalone version of Loco_hooks_LoadHelper
<?php
/*
Plugin Name: Loco Standalone Loader
Description: Mimics Loco_hooks_LoadHelper without dependency on the main plugin
Author: Tim Whitlock
Version: 1.0
*/
new LocoStandaloneLoadHelper;