Skip to content

Instantly share code, notes, and snippets.

View zacscott's full-sized avatar

Zac Scott zacscott

View GitHub Profile
@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;
@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.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 / 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 / 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 / Assertions.java
Last active December 18, 2015 14:19
A simple facility to support design-by-contract principles (in Java).
package net.zeddev.util;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* A simple facility to support design-by-contract principles.
* Significantly smaller and simpler than other more heavy-weight frameworks
* (such as contract2j, OVal, etc) but provides better functionality over the
@zacscott
zacscott / NamedLog.java
Last active December 18, 2015 00:29
A wrapper for the android log, providing a more robust, useful interface.
package net.zeddev.android.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import android.util.Log;
@zacscott
zacscott / FastCache.java
Last active December 16, 2015 18:09
A small, compact in-memory cache designed for high data throughput.
package net.zeddev.util;
import java.lang.ref.SoftReference;
import java.lang.reflect.Array;
/**
* <p>
* A small, compact in-memory cache designed for high data throughput.
* The cache can be simply integrated with existing source using the following
* pattern;
@zacscott
zacscott / HashUtil.java
Last active December 16, 2015 16:49
A utility to assist in creating hashCode() implementations (in Java).
package net.zeddev.util;
import java.lang.reflect.Field;
/**
* <p>
* A utility to assist in creating <code>hashCode()</code> implementations.
* Can simply be used like so;
* </p>
*
@CodeNegar
CodeNegar / gist:3713606
Created September 13, 2012 11:06
php: fuzzy time ago
<?php
function prettyDate($date){
$time = strtotime($date);
$now = time();
$ago = $now - $time;
if($ago < 60){
$when = round($ago);
$s = ($when == 1)?"second":"seconds";
return "$when $s ago";
}elseif($ago < 3600){