Skip to content

Instantly share code, notes, and snippets.

Avatar

Wayne K. Walrath wkw

View GitHub Profile
@wkw
wkw / wavefilereader.class.php
Created Dec 7, 2017 — forked from RobThree/wavefilereader.class.php
PHP WAVE file reader / parser
View wavefilereader.class.php
<?php
/**
* WaveFileReader; a simple class to read/parse WAVE file
* (c)2012 Rob Janssen / https://github.com/RobThree
*
* Based on https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
*
* USAGE:
*
* $wav = WaveFileReader::ReadFile('/path/to/test.wav');
@wkw
wkw / array-to-texttable.php
Created Sep 29, 2017 — forked from tony-landis/array-to-texttable.php
PHP: Array to Text Table Generation Class
View array-to-texttable.php
<?php
/**
* Array to Text Table Generation Class
*
* @author Tony Landis <tony@tonylandis.com>
* @link http://www.tonylandis.com/
* @copyright Copyright (C) 2006-2009 Tony Landis
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class ArrayToTextTable
@wkw
wkw / wordpress-tinymce.js
Created Sep 28, 2017 — forked from RadGH/wordpress-tinymce.js
Get/Set content of a TinyMCE visual or text editor with JavaScript
View wordpress-tinymce.js
/*
Based on: http://wordpress.stackexchange.com/questions/42652/#answer-42729
These functions provide a simple way to interact with TinyMCE (wp_editor) visual editor.
This is the same thing that WordPress does, but a tad more intuitive.
Additionally, this works for any editor - not just the "content" editor.
Usage:
@wkw
wkw / macos-get-ip-address.php
Last active Mar 28, 2020
Mac OS Get Wi-Fi IP address (cmd line or php)
View macos-get-ip-address.php
<?php
# SOURCE: https://apple.stackexchange.com/a/226880
$ip = trim(exec("ipconfig getifaddr $(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}')", $out, $rc));
echo "$ip\n";
@wkw
wkw / fresh-chrome.sh
Last active Nov 17, 2017 — forked from stuartsierra/fresh-chrome.sh
Launch new instances of Google Chrome on OS X with isolated cache, cookies, and user config
View fresh-chrome.sh
#!/usr/bin/env bash
# fresh-chrome
#
# Use this script on OS X to launch a new instance of Google Chrome
# with its own empty cache, cookies, and user configuration.
#
# The first time you run this script, it will launch a new Google
# Chrome instance with a permanent user-data directory, which you can
# customize below. Perform any initial setup you want to keep on every
@wkw
wkw / gist:35f75406b6b38ea3eaa1bd114c1e7ed0
Created Feb 3, 2017 — forked from samnang/gist:1759336
Install Bash version 4 on MacOS X
View gist:35f75406b6b38ea3eaa1bd114c1e7ed0
# Install Bash 4 using homebrew
brew install bash
# Or build it from source...
curl -O http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz
tar xzf bash-4.2.tar.gz
cd bash-4.2
./configure --prefix=/usr/local/bin && make && sudo make install
# Add the new shell to the list of legit shells
@wkw
wkw / wp-parent-page-filter.php
Created Oct 25, 2016
WordPress: allow draft, private posts to be selected in Parent page dropdown
View wp-parent-page-filter.php
/**
* Show draft and private pages in hierarchicial Parent pages dropdown.
* will work for any hier. post type.
*/
function filter_attributes_dropdown_pages_args($dropdown_args) {
$dropdown_args['post_status'] = array('publish','draft', 'private');
return $dropdown_args;
}
add_filter('page_attributes_dropdown_pages_args', __NAMESPACE__ . '\\filter_attributes_dropdown_pages_args', 100, 1);
@wkw
wkw / merge-package-json.js
Last active Oct 12, 2016
Nodejs shell script to merge portions of one package.json to another one. requires shelljs and chalk NPM packages. Originally written to Merge EMN Reagent React client package with an ExpressJS Server package.json.
View merge-package-json.js
#!/usr/bin/env node
/* global test, cp, exec */
require('shelljs/global');
const chalk = require('chalk');
const format = require('util').format;
const path = require('path');
const writeFile = require('fs').writeFileSync;
// colorize output...
const chalkError = chalk.bold.red;
View opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost
@wkw
wkw / gravity-form.php
Last active Nov 16, 2020 — forked from OutThisLife/gravity-form.php
Custom: Gravity Forms WP API Submission and GF API form entry creation plus send notifications
View gravity-form.php
<?php
/**
* Add WP API endpoint for form submission, then create new
* Gravity Forms entry and send notifications.
*/
// rest api endpoint for forms submission
add_action( 'rest_api_init', function () {
register_rest_route( 'ahr/v1', '/forms', array(
'methods' => 'POST',
You can’t perform that action at this time.