Skip to content

Instantly share code, notes, and snippets.

View zacscott's full-sized avatar

Zac Scott zacscott

View GitHub Profile
@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>
*
@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 / SimpleDialog.java
Last active December 17, 2015 03:38
Provides some common swing dialogs in Java.
package net.zeddev.util;
import java.awt.Frame;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import java.util.logging.Logger;
/**
* <p>
@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 / 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 / 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 { }