Skip to content

Instantly share code, notes, and snippets.

dalethedeveloper /
Created Dec 16, 2016
Extract a single WP Multisite Side DB Files
if [ $# -ne 1 ]
echo "Enter a WPMU ID for the Database"
DBS=$(mysql -u $WPUSER -p -ss $WPDBNAME -e "SHOW TABLES LIKE 'wp_$1_%'" | tr "\n" " ")
$(mysqldump -u $WPUSER -p $WPDBNAME $DBS > wp_$1_sql)
dalethedeveloper / gist:8bbc30e847543fac088b
Created Jan 12, 2015
Plain Javascript to normalize target attribute for External Links
View gist:8bbc30e847543fac088b
// I needed to trigger a non-interactive Google Analytics Event on external link click in
// Google Tag Manager v2. This is a hacky workaround for targeting external links on using
// a trigger like this:
// Event Type: Link Click [element: target] [starts with] ["_"]
// This is used as a HTML tag in Google Tag Manager v2 to normalize all external <A> links
// to have a "target" attribute. Priority 100, Triggered on All Pages and Event = gtm.dom
dalethedeveloper / gist:cc1f482f5ebdf07ccf26
Last active Aug 29, 2015
Prepare a Tab Delimited flat file for SQL Import where text fields contain newlines that cause records fall to the next line
View gist:cc1f482f5ebdf07ccf26
# Assumes a tab delimited flat file and the first field being a numeric key
FS = OFS = "\t";
p = "";
# Strategy is to readline, check for key in first field, store to print
# on next readline if the next record has a key in first field, otherwise
# append our fragmented line to the stored line
sub(/\r/,""); # also scrub those pesky carriage returns
dalethedeveloper / gist:460e7c72c1d1e9f55a94
Created Dec 12, 2014
Check the Google Tag Manager dataLayer for an Ecommerce transaction and do something only once (cookie enforced)
View gist:460e7c72c1d1e9f55a94
if (typeof (window.dataLayer) !== 'undefined' && window.dataLayer.length) {
for (var d = 0; d < window.dataLayer.length; d++) {
var obj = window.dataLayer[d],
keys = Object.keys(obj);
for (var k = 0; k < keys.length; k++) {
var key = keys[k],
val = obj[key];
dalethedeveloper / gist:0ce24d86cf4c4a12e277
Created Oct 1, 2014
Poor Mans Image Rotator (multiple slides, minimal jquery)
View gist:0ce24d86cf4c4a12e277
<!DOCTYPE html>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//"></script>
var rollem = function() {
var si = $('#slide ul.current');
dalethedeveloper / .htaccess
Created May 15, 2014
WordPress .htacces redirect to shift to new domain but allow wp-admin access
View .htaccess
# Drop at the end of your base .htaccess or virtualhost, hooray for negative lookaheads
RedirectMatch ^\/(?!wp\-admin)(.*)$$1
dalethedeveloper / functions.php
Created Jan 20, 2014
Remove height= and width= attributes on IMG tags generaged by WordPress :: the_thumbnail() calls.
View functions.php
function strip_img_hwattr($html) {
return preg_replace('/(width|height)=\"\d+\"\s/','',$html);
dalethedeveloper / .htaccess
Created Jan 16, 2014
Power up PHP on Rackspace Cloudsites, WordPress is hungry
View .htaccess
# append to existing .htaccess
# PHP Settings
php_value memory_limit 512M
php_value upload_max_filesize 32M
php_value post_max_size 32M
php_value max_execution_time 200
php_value max_input_time 200
dalethedeveloper / gist:8336483
Created Jan 9, 2014
WordPress wp-config.php hack to force a WP site to respond to whatever domain you access it from, database wp_options be damned. Thanks Rackspace Cloud Sites!
View gist:8336483
// Anywhere in the wp-config.php before the last include
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
dalethedeveloper / gist:7539297
Created Nov 19, 2013
Hackery to migrate existing GIT repositories to BitBucket as the master origin. Say you have a directory of folders, each with a git repository, that need to be created as private repositories and pushed up. This does that.
View gist:7539297
# Get your credentials set in your environment before you run:
# export BB_USER="my_username"
# export BB_P="MySERCRETP4ss"
# export BB_OWNER="my_username_or_team"
for f in $(find -type d -path '.*git' |cut -d'.' -f2|sed 's:/::g'); do
g=$(curl -s -u $BB_USER:$BB_P "$BB_OWNER/$f")
rg=$(echo "$g" | grep -c error)