Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
@DrewAPicture
DrewAPicture / git.sh
Created May 30, 2013 03:59
Branch highlighting
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\u@machine$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ "
@DrewAPicture
DrewAPicture / first.css
Created June 13, 2013 17:54
Working with this list of footer links (it's coming from a wp_nav_menu() call), I need to select only the first href inside the first list item.
<nav>
<div>
<ul>
<li>
<a href="#">First</a>
</li>
<li>
<a href="#">Second</a>
</li>
<li>
@DrewAPicture
DrewAPicture / 36_props.sh
Last active December 19, 2015 13:09
WordPress props between two revisions. Requires ack or grep (just replace ack calls with grep).
svn log http://develop.svn.wordpress.org/trunk -r 26861:HEAD | ack -i "props" | ack -ic "DrewAPicture"
@DrewAPicture
DrewAPicture / ww_svn_log_props.php
Last active December 19, 2015 13:18
SVN log props counter. WordPress function to trawl the commits log and count props. Counts are more accurate after removing the array_reduce(). Still not totally accurate.
<?php
/**
* List contributor props from most to least
*
* @param string $url (optional) The SVN repo URL.
*/
function ww_svn_log_props( $url = 'http://core.svn.wordpress.org/trunk' ) {
$log = get_transient( '36_log' ); // 12 Hour transient
if ( ! $log ) {
$log = shell_exec( 'svn log -r 23171:HEAD --xml ' . esc_url( $url ) );
@DrewAPicture
DrewAPicture / plugin_repo_bookmarklet.html
Last active December 19, 2015 18:09
Plugin Repo bookmarklet. Clicking this bookmarklet while on any WordPress.org-hosted plugin page or sub-page will jump you to the trunk directory of that plugin's SVN repository..
<a href="javascript:(function(){var split=window.location.pathname.split('/');location.href='http://plugins.svn.wordpress.org/' + split[2] + '/trunk/'})();">Plugin Repo</a>
for i in `cat unusual.txt`; do echo "$RANDOM $i"; done | sort | sed -E 's/^[0-9]+ //' > randorder.txt
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
@DrewAPicture
DrewAPicture / gistmerge.sh
Last active August 15, 2016 18:12
Script to merge a Gist fork into your original. You'll need the id of your Gist and the id of the fork.
#!/bin/bash
# usage: ORIG=###### NEW=###### ./gistmerge.sh
# $ORIG = The Gist ID of your Gist
# $NEW = The Gist ID of the fork
# Note: chmod u+x gistmerge.sh may be necessary
# if you're getting permissions errors
printf "\n\n... Cloning original Gist.\n\n"
@DrewAPicture
DrewAPicture / gist:6141436
Last active December 20, 2015 13:48
Post Formats + other removed functions and filters in 3.6
http://codex.wordpress.org/Function_Reference/get_attached_audio
http://codex.wordpress.org/Function_Reference/get_attached_video
http://codex.wordpress.org/Function_Reference/get_attached_images
http://codex.wordpress.org/Function_Reference/get_attached_image_srcs
http://codex.wordpress.org/Function_Reference/get_content_media
http://codex.wordpress.org/Function_Reference/get_content_audio
http://codex.wordpress.org/Function_Reference/get_content_video
http://codex.wordpress.org/Function_Reference/get_content_images
http://codex.wordpress.org/Function_Reference/get_content_image
http://codex.wordpress.org/Function_Reference/get_content_galleries
@DrewAPicture
DrewAPicture / functional.php
Last active December 21, 2015 23:19
Functional array docs ideas
<?php
/**
* @param array $date_query {
* @type string 'column' (optional) Column to query against, default is 'post_date'.
* @type string 'compare' (optional) Comparison operator, defaul is '='. @see WP_Date_Query::get_compare()
* @type string 'relation' (optional) How the sub-arrays should be compared, accepts 'AND' (default) or 'OR'.
* }