Retrieving a password you accidentally deleted from your OS X Stickies

If you are careless, you regularly delete stickies containing important information. Thankfully, your Tax ID code is a 12-digit number.

# OSX may have left an old copy of the stickies lying around. this is where we will look.
# get the stickies and back them up
$ cd /Users/[you]/Library/Preferences/
$ mkdir ~/stickybackup
$ cp *.stickies.plist* ~/stickybackup
$ cd ~/stickybackup
# we want to grep the .plist files, but they're technically binary blobs
# so we must convert them. repeat for each file - i can't write bash loops
$ plutil -convert xml1 -o - [your sticky filename] > plain_text.txt
$ grep '[0-9]\{12\}' plain_text.txt 

cf: and

Drive-by recursion in PHP

PHP does not make it easy to program with recursion offhand, but it’s possible. This is from a WordPress function which needed to get IDs from terms and all their parents:

// get the term ids from this term and all its parents
$all_ids = call_user_func($func = function( $term, $ids ) use ( &$func ) {
    if( !$term ) { return $ids; }

    $ids[] = $term->term_id;
    $next_term = get_term_by( 'id', $term->parent, $term->taxonomy );

    return call_user_func( $func, $next_term, $ids );
}, $term, array() );