Skip to content

Instantly share code, notes, and snippets.

View pjdietz's full-sized avatar

PJ Dietz pjdietz

View GitHub Profile
@pjdietz
pjdietz / MySQL.sublime-build
Created May 2, 2014 19:50
MySQL configuration file
{
"cmd" : ["mysql --defaults-file={path to mysite.my.conf} -t < $file >> /tmp/output.sql ; subl /tmp/output.sql"],
"shell" : true,
"path" : "/usr/local/bin:~/bin:$PATH"
}
@pjdietz
pjdietz / gist:17c19d5a36d808c24a73
Created May 27, 2014 13:39
WoW: Find quest IDs complete by a character
http://us.battle.net/api/wow/character/{realm}/{character}?fields=quests
@pjdietz
pjdietz / CountDown.java
Last active August 29, 2015 14:02
Java class that performs an operation after a predetermined number of actions occur.
import java.util.concurrent.atomic.AtomicInteger;
/**
* Performs an operation after a predetermined number of actions occur.
*/
abstract public class CountDown {
private AtomicInteger count;
/**
@pjdietz
pjdietz / DirectoryAutoloader.php
Last active August 29, 2015 14:04
PHP class for autoloading classes from a specific directory.
<?php
/**
* Allow PHP to autoload classes from a specific directory.
*
* https://gist.github.com/pjdietz/05f1fcef4ca3bd7d6448
*
* Classes MUST be one class or interface per file with the name of the class or interface matching the filename
* (minus .php).
*
@pjdietz
pjdietz / RefResolver.php
Created July 22, 2014 19:58
$ref Resolver
<?php
/**
* Iterates through an object or array and resolves or "flatten" and $ref
* properties by reading the object the reference points to and augmenting
* the containing object with the result.
*
* This class works with any stdClass object, but is mostly likely to be
* useful for working with JSON Schema documents and Swagger configurations.
*/
@pjdietz
pjdietz / RedirectException.php
Created August 14, 2014 20:41
PHP Exception for handling redirection
<?php
/**
* Exception to indicate the response should redirect to a different URI.
*/
class RedirectException extends \Exception
{
/** @var int Status code */
protected $code = 302;
/** @var string URI to use in the Location header */
protected $message = "/";
@pjdietz
pjdietz / prettyjson
Created March 11, 2015 14:53
Pretty Print JSON
#!/usr/bin/env php
<?php
$input = file_get_contents("php://stdin");
$data = json_decode($input);
if (is_null($data)) {
fwrite(STDERR, "Unable to parse JSON\n");
exit(1);
}
print json_encode($data, JSON_PRETTY_PRINT);
@pjdietz
pjdietz / install-composer.sh
Last active August 29, 2015 14:16
Install Composer
# Install composer to /usr/loca/bin/composer
curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin
# With sudo
curl -sS https://getcomposer.org/installer | sudo php -- --filename=composer --install-dir=/usr/local/bin
# For scripting, install or self-update
if type composer &> /dev/null; then
composer self-update
else
@pjdietz
pjdietz / post-checkout
Created March 12, 2015 18:34
Run composer install after checkout
composer install || php composer.phar install || php ~/composer.phar install || echo "Please run composer install"
@pjdietz
pjdietz / refCount.php
Last active August 29, 2015 14:17
Return the number of references for a variable's zval
<?php
/**
* Return the number of references for a variable's zval
*
* @param mixed $var Variable to inspect
* @return int Number of references according to debug_zval_dump
*/
function refCount($var)
{