Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / remove_empty_descendants.php
Created December 23, 2016 17:41
Iterative post-order traversal of the DOM to remove empty nodes.
<?php
/**
* Post-order traversal of the dom starting at given node. Remove any
* nodes that have no children and no attributes. Nodes named in the
* AMP_Rule_Spec::node_types_to_allow_empty array will not be removed.
*/
private function remove_empty_descendants( $node ) {
$stack = array();
$next_traversal = 'child';
$nodes_to_remove = array();
@delputnam
delputnam / get_dir.sh
Created December 27, 2016 13:29
Get directory of bash script
pushd `dirname $0` > /dev/null
SCRIPT_DIR=`pwd`
popd > /dev/null
@delputnam
delputnam / bash-file-loop.sh
Created December 27, 2016 13:30
Loop through files in bash script
for file in /dir/*
do
# command
done
@delputnam
delputnam / gist:ece1350f6079225cc5de3acfee526059
Created January 6, 2017 12:10
Get paths of all image sizes for post attachments
$args = array(
'posts_per_page' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $post_id,
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
foreach( $attachments as $attachment ) {
@delputnam
delputnam / happy_git_on_osx.md
Created January 17, 2017 18:42 — forked from trey/happy_git_on_osx.md
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

@delputnam
delputnam / jetpack-test.php
Last active January 23, 2018 20:16
A simple WordPress plugin to allow testing of Jetpack's Related Posts module
<?php
/**
* @package Jetpack_Test
* @version 1.0
*/
/*
Plugin Name: Jetpack Test
Description: Allows certain Jetpack modules that would otherwise require a connection to WordPress.com to be run in a local development environment.
Author: Del Putnam
@delputnam
delputnam / gist:8213bbe304b9ffbdcfc28f5d6b083e8c
Last active December 15, 2022 19:29
Remove all unison .tmp files
find . -name "*.unison.tmp" -delete
@delputnam
delputnam / gist:40c4c777707c292cf8f961663770d58d
Created April 28, 2017 14:49
save and apply svn diffs locally
svn diff > ~/my-awesome-diff.diff
patch -p0 < ~/my-awesome-diff.diff
@delputnam
delputnam / gist:497ee68b4f2df9301ba4eb9753fb0b0f
Created May 10, 2017 14:32
svn remove unversioned files
svn status | grep ^\? | cut -c9- | xargs -d \\n rm -r
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem