Skip to content

Instantly share code, notes, and snippets.

View zacscott's full-sized avatar

Zac Scott zacscott

View GitHub Profile
@zacscott
zacscott / AnnotatedLogger.java
Last active December 21, 2015 05:09
A simple utility which produces java.util.logging.Logger's using a consistent, logical naming scheme using class annotations. MIT licensed.
package net.zeddev.util;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
@zacscott
zacscott / RunLoopedThread.java
Last active December 21, 2015 05:18
A simple Java utility for a the common run loop thread idiom. You will need some of the other utilities which I have create gists for.
package net.zeddev.util;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.zeddev.util.AnnotatedLogger.LogName;
import static net.zeddev.util.Assertions.*;
/**
* <p>
@zacscott
zacscott / prettyJSON.php
Last active December 24, 2015 05:18
Converts to JSON, in a pretty, human readable format (yet still valid JSON).
<?php
/**
* Converts to JSON, in a 'pretty', human readable format (yet still
* valid JSON).
*
* This code was modified from this GitHub
* <a href="https://gist.github.com/GloryFish/1045396">Gist</a>.
*
* @param string $json The JSON code to prettify.
@zacscott
zacscott / preload.js
Last active December 27, 2015 14:49
jQuery plugin to preload images.
/** jQuery plugin to preload images */
$.fn.preload = function() {
this.each(function(){
$('<img/>')[0].src = this;
});
}
// use like so:
$(['img/pic1.jpg', 'img/pic2.jpg', ...]).preload();
@zacscott
zacscott / class.Uploader.php
Last active December 29, 2015 10:09
Utility to handle file uploads.
<?php
namespace \net\zeddev\util;
/** An error while uploading. */
class UploaderException extends \Exception { }
/** An invalid type for uploaded file. */
class UploaderTypeException extends UploaderException { }
@zacscott
zacscott / class.Thumbnailer.php
Last active December 29, 2015 10:09
Simple utility which dynamically creates thumbnail/preview images.
<?php
namespace \net\zeddev\util;
/**
* A simple utility to dynamically create thumbnail images. Images can be
* stored on disk, or served on the fly (depending how constructed). For
* example:
*
* $ondisk = new Thumbnailer('thumbnail/dir/path');
@zacscott
zacscott / class.XSRFToken.php
Last active December 30, 2015 04:49
Utility to prevent cross-site request forgeries (XSRF).
<?php
namespace net\zeddev\util;
// start session if not already
if (session_id() == '')
session_start();
/**
* Utility to prevent cross-site request forgeries (XSRF) using a request scoped
@zacscott
zacscott / fuzzyDate.php
Last active January 2, 2016 19:09 — forked from CodeNegar/gist:3713606
Fuzzy/approx of a date in the past (php function).
<?php
/** Returns a fuzzy/approx of a date in the past. */
function fuzzyDate($date){
$time = strtotime($date);
$now = time();
$ago = $now - $time;
if ($ago < 60) {
@zacscott
zacscott / routes.php
Last active March 11, 2017 01:23
Simple one file router for WordPress (can be used as a mu-plugin)
<?php
/*
* Plugin Name: Routes for WordPress
* Description: Routes class provider plugin
* Version: 2.0
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / purge-cache.php
Last active March 11, 2017 11:07
Allow admins to purge the WordPress cache
<?php
/**
* Plugin Name: Purge Cache
* Description: Allow admins to purge the WordPress cache
* Version: 1.1
* Author: Zachary Scott
*/
namespace zacscott;