Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / class-estimator.php
Last active March 15, 2019 00:26
Time Left Estimator
<?php
/**
* Estimator class to get estimated time left.
*/
class Estimator {
public $total = 0;
public $count = 0;
public $start_time = 0;
@petenelson
petenelson / object-cache.php
Last active February 21, 2024 22:40
object-cache.php for memcached
<?php
/**
* Adds a value to cache.
*
* If the specified key already exists, the value is not stored and the function
* returns false.
*
* @link http://www.php.net/manual/en/memcached.add.php
*
* @param string $key The key under which to store the value.
@petenelson
petenelson / ssh-mysql-tunnel-test.php
Created July 13, 2017 16:10
WordPress: MySQL PDO command via SSH tunnel
<?php
/**
* Plugin Name: SSH Remote Test
*/
add_action( 'admin_init', 'ssh_remote_test', 1 );
function ssh_remote_test() {
@petenelson
petenelson / ssh-remote-command.php
Created July 12, 2017 21:27
WordPress: Run SSH command remotely
<?php
/**
* Plugin Name: SSH Remote Test
*/
add_action( 'admin_init', 'ssh_remote_test', 1 );
function ssh_remote_test() {
@petenelson
petenelson / bacon.sh
Last active May 3, 2017 21:53
Get paragraphs of garbage content from baconipsum.com
#!/bin/bash
#####################
# bacon.sh
#
# Client to get paragraphs of garbage content from baconipsum.com
#
# usage:
# bacon.sh <paragraph-count>
#####################
@petenelson
petenelson / userhtml.wcc
Created March 15, 2017 07:27
UserHTML - Some Wildcat BBS code I wrote back in 1995
// USERHTML - Wildcat User List to HTML Converter
// By: Pete Nelson ([email protected])
dim urec as userrecord
dim today as date, now as time, domain as string
if not exists("userhtml.cfg") then
cls
print "@0A@What is your domain name@07@: " defcolor;
@petenelson
petenelson / rest-api-route-array-schema.php
Created February 27, 2017 19:46
WordPress: Example of REST API route with schema type of array
<?php
register_rest_route( 'test', '/v1/schema-test', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\handle_endpoint',
'args' => array(
'mybools' => array(
'required' => true,
'type' => 'array', // We require an array of items.
'items' => array(
@petenelson
petenelson / cached-wp-nav-menu.php
Created February 3, 2017 19:19
WordPress: Cached navigation menu helper function
<?php
/**
* Helper functions for caching WordPress navigation menu HTML.
*/
namespace PeteNelson\Navigation;
add_action( 'init', __NAMESPACE__ . '\setup' );
/**
@petenelson
petenelson / backup_github_to_s3.sh
Last active January 22, 2023 19:57
Bash script: Backup GitHub Repos to S3
#!/bin/bash
DATE=$(date "+%Y-%m-%d")
GITHUB_OWNER=petenelson
BACKUPS_DIR=~/backups
TAR_FILE=github-repos-$DATE.tar.gz
S3_BUCKET=s3://github-offsite-backup
# Creates a directory if it doesn't exist
# $1: dir path
@petenelson
petenelson / wordpress-localize-script.php
Last active June 1, 2023 16:43
WordPress Localize Script Example
<?php
add_action( 'wp_enqueue_scripts', 'add_localized_js_data' );
function add_localized_js_data() {
wp_enqueue_script( 'my-frontend-script-handle', 'url to my frontend Javascript', array( 'jquery' ) );
$data = array(
'ajax_url' = admin_url( 'admin-ajax.php' ),