Grunting Your Way to Success (Wordcamp Boston 2014)

August 23, 2014

I had a blast talking about the amazingness of Grunt at WordCamp Boston 2014. I’ll be posting the video once it’s online, but in the meantime, here are the slides!

Git for Five Year Olds (Wordcamp Boston 2013)

October 27, 2013

I gave a talk at Wordcamp Boston 2013 titled Git for Five Year Olds. It was focused on serving as a Git introduction for people who had never even heard of Git before, or had used it but felt like they might have missed some of the important concepts.

Here are the slides.

Below are some of the resources I mentioned in the talk, and that I find helpful for anyone learning or using Git.

Git Tutorials


Git GUI Clients

Git Repository Hosting (i.e. Remotes)

Querying Wordpress Custom Fields and Including Null Values

June 12, 2013

I was having a heck of a time writing a query that would include any posts with a custom field whose value was set to “updated”, “new”, or null. Unfortunately the method suggested in the codex for WP_Query assumes that there will always be a value in the field. If the field is null, it won’t include those posts.

I looked at running a SQL query on the database to fill in those fields, but the wp_postmeta table in Wordpress doesn’t seem to have any kind of 1-to-1 relationship to the pages.

After some poking around, I found this great post entitled Querying posts with a false or NULL meta value. I modified the code to match my criteria:

function lets_modify_the_posts_where( $clause='' ) {
    global $wpdb;
    // Check whether the value is false or NULL. If it is neither, then we want to filter it.
    $clause .= " AND ( (my_postmeta.meta_key = 'update_type' AND ( CAST(my_postmeta.meta_value AS CHAR) = 'updated' OR CAST(my_postmeta.meta_value AS CHAR) = 'new')) OR my_postmeta.meta_id IS NULL ) ";
    return $clause;

I also like how it uses filters to inject SQL instead of modifying the ‘meta_query’ key, which apparently can cause issues if you have plugins which use that.

Remove Line Breaks in a SQL Query

June 05, 2013

Break Line

I work with a lot of databases (specifically, T-SQL databases) which collect form submissions in which there is a pretty large comment field. Being that this is a textarea, often people make liberal use of line breaks. Unfortunately, this wreaks havoc when you try to either copy the results from the query into Excel, or export to a CSV and then import to Excel. Even when you force double quotes around each column, Excel still happily creates a new row whenever it sees a line break.

The solution I found was to modify the SELECT query to remove the two character entities representing line breaks and new lines in T-SQL, which are CHAR(13) and CHAR(10). This should cover your bases for the new line characters CR, LF, and CR+LF.

The specific SQL looks like this:

SELECT REPLACE(REPLACE(@str, CHAR(13), ' '), CHAR(10), ' ')

You can, of course, replace the line breaks with something besides a single space, but I found that the best option in terms of maintaining readability in those fields once they’re in a CSV.

Source: Replacing a newline in TSQL

Splitting Music from an iTunes Library

December 01, 2012

My wife has a MacBook Air, which she loves dearly, but sadly we didn’t anticipate just how much space she needed when we got the 128GB version.

However, she just started recently using Rdio, and so she doesn’t really have much need for keeping all of those music files on her hard drive. Moving them to an external hard drive would be fine for those times that she needed them.

That’s easier said than done though. It’s easy enough to move the entire library to an external drive. But she doesn’t want that, because she uses iTunes all the time for books and doesn’t want to hook up the external drive each time she does that.

Here’s the best method I could put together for moving the physical MP3 files to the external drive, update the iTunes library to point to that location, and leave everything else as it is.

  1. To be safe, backup both the iTunes Library.itl file, and the iTunes Music Library.xml file. Copy the iTunes Music Library.xml file and name it something new.
  2. In iTunes, make sure the organize library and copy files options are disabled (under Preferences->Advanced).
  3. Copy all of the MP3s to the external drive. Any directory will do.
  4. Delete all of the music from iTunes, and allow it to move those files to the trash (since we just copied all of that to our external drive). Quit iTunes.
  5. Open up the new iTunes Music Library.xml file that you copied in step one. You’ll see repeated references to “file://localhost/”, which continues with the path to your local music directory. Replace that URL with the new directory, which should look something like “file://localhost/Volumes/External%20HD/Music”
  6. Open iTunes again and click File->Library->Import Playlist. Select the .xml file we just modified.

And that’s it. The only issue I see with this is that I believe if you enable the option to organize the library, it will copy all of the files back to the local hard drive.