A Better WordPress Singleton

class PluginClass
{
    public static $instance = null;
    
    public static function init()
    {
        if ( null === self::$instance ) {
            self::$instance = new PluginClass();
            self::$instance->boot();
        }

        return self::$instance;
    }
    
    protected function __construct()
    {
        // Startup
    }
    
    protected function boot()
    {
        // Boot
    }
}

PluginClass::init();
class PluginClass
{
    protected static $instance = null;
    
    public function __construct($file)
    {
        if (static::$instance !== null) {
            throw new Exception;
        }

        static::$instance = $this;
    }

    public static function get()
    {
        return static::$instance;
    }
}
call_user_func(array(new PluginClass(__FILE__), 'boot'));

Get list of apps missing from Kitchenplan

var exec = require('child_process').exec;
var grep = require('grep1');

var callback = function(error, stdout, stderr) {
    if (error) {
        return console.error(error);
    }

    installed = stdout.split('\n');

    installed.forEach(function(app) {
        if (!app) {
            return;
        }

        grep(['-nr', app, '/opt/kitchenplan'], function(err, stdout, stderr) {
            if (err) {
                console.log('* ' + app);
            }
        });
    });
};

exec('brew list', callback);
exec('brew cask list', callback);

Facebook Post Debugger

<?php
/*
Plugin Name: Facebook Post Debugger
Version: 0.1
Plugin URI: http://jamesdigioia.com/
Description: This plugin runs the bit.ly shortlink through the Facebook debugger upon publishing.
Author: James DiGioia
Author URI: http://www.jamesdigioia.com/
*/

add_filter( 'publish_post', 'fb_debug_link' );

function fb_debug_link( $post ) {
  $short = wp_get_shortlink($post['id']);
  $url = 'https://graph.facebook.com/?id='.$short.'&scrape=true';
  wp_remote_post( $url );
}

WordPress Site Boilerplate

{"name":"name\/site","type":"project","license":"MIT","description":"A modern WordPress stack for Name.com","homepage":"http:\/\/name.com\/","authors":[{"name":"James DiGioia","email":"jamesorodig@gmail.com","homepage":"https:\/\/jamesdigioia.com\/"}],"repositories":[{"type":"composer","url":"http:\/\/wpackagist.org"}],"require":{"php":">=5.4","johnpbloch\/wordpress":"4.1.1","wpackagist-theme\/casper":"1.1.0","wpackagist-plugin\/akismet":"3.0.3","wpackagist-plugin\/batcache":"1.2","wpackagist-plugin\/backwpup":"3.1.2","wpackagist-plugin\/limit-login-attempts":"1.7.1","wpackagist-plugin\/media-file-renamer":"1.9.4","wpackagist-plugin\/post-thumbnail-editor":"2.4.2","wpackagist-plugin\/wordpress-seo":"1.6.3","wpackagist-plugin\/wp-smushit":"1.6.5.4","composer\/installers":"v1.0.12","vlucas\/phpdotenv":"~1.0.6","wp-sync-db\/wp-sync-db":"dev-master#c0475de77ca28891a35726eee7d30f9c0d804ba0","wp-sync-db\/wp-sync-db-media-files":"dev-master#f49c90ff8716b80bfbcc650212fd3f583d06f234","wp-sync-db\/wp-sync-db-cli":"dev-master#28188ea6c4081e5bd322e9c14bbfc4946d5dcb73"},"require-dev":{"wpackagist-plugin\/debug-bar":"0.8.2","wpackagist-plugin\/debug-bar-console":"0.3","wpackagist-plugin\/debug-bar-cron":"0.1.2","wpackagist-plugin\/debug-bar-extender":"0.5","wpackagist-plugin\/log-deprecated-notices":"0.3","wpackagist-plugin\/rewrite-rules-inspector":"1.2.1"},"extra":{"installer-paths":{"web\/app\/mu-plugins\/{$name}\/":["type:wordpress-muplugin"],"web\/app\/plugins\/{$name}\/":["type:wordpress-plugin"],"web\/app\/themes\/{$name}\/":["type:wordpress-theme"]},"wordpress-install-dir":"web\/wp"}}

userAgent checking

// Source: https://github.com/pixelcog/parallax.js/blob/master/parallax.js#L96
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
    // if iOS
}

if (navigator.userAgent.match(/(Android)/)) {
    // if Android
}

ParseCSV Image Downloading

require("ParseCSV.php");

$csv = new ParseCSV("youtube-images.csv");
$n = 1;
foreach($csv->data as $data) {
  if(false != file_put_contents("pics/{$data['filename']}.jpg", file_get_contents($data['url']))) {
    $log = "File {$n}: Downloaded {$data['filename']} from {$data['url']}n";
  } else {
    $log = "File {$n}: Download from {$data['url']} failedn";
  }
  print $log;
  file_put_contents("output.log", $log, FILE_APPEND | LOCK_EX);
  $n++;
}