Skip to content

Instantly share code, notes, and snippets.

View ClickerMonkey's full-sized avatar
💭
VPLs, ORMs, and Bag End

Philip Diffenderfer ClickerMonkey

💭
VPLs, ORMs, and Bag End
View GitHub Profile
@ClickerMonkey
ClickerMonkey / Compress.java
Created November 18, 2013 19:46
Compressed put/get operations on a ByteBuffer for byte, char, short, int, long, Byte, Character, Short, Integer, and Long.
import java.nio.ByteBuffer;
public class Compress
{
public static final int BYTE_MORE = 0x80;
public static final int BYTE_SIGN = 0x40;
public static final int BYTE_NULL = 0x20;
@ClickerMonkey
ClickerMonkey / Reflect.java
Created November 18, 2013 19:51
Custom object serialization with compression (requires Compress.java) to and from ByteBuffers.
public interface Reflect<T>
{
public T get(ByteBuffer in);
public void getAndSet(ByteBuffer in, Object obj, Field field) throws IllegalAccessException;
public void put(ByteBuffer out, T v);
public int sizeOf(T v);
@ClickerMonkey
ClickerMonkey / Blend.java
Created November 18, 2013 19:58
Software graphics library with blending, textures, and simple primitives.
public abstract class Blend
{
public static final Blend Alpha = new Blend()
{
public int blend( int o, int n )
{
return Color.mixRGB( o, n, Color.alpha( n ), Color.alpha( o ) );
}
};
@ClickerMonkey
ClickerMonkey / Prime.java
Created November 18, 2013 20:04
A prime number utility for generating X number of primes, determining whether a given number is prime, and computing the prime factorization for a number. This class caches primes to very quickly check whether a number is a prime.
public class Prime
{
/* BEGIN TEST */
public static void main( String[] args )
{
Prime p = new Prime( 100000 );
// Load 100,000 primes into cache
long t0 = System.nanoTime();
@ClickerMonkey
ClickerMonkey / LinkedList.java
Created November 18, 2013 20:11
Doubly linked-list where nodes can remove themselves instantly from their list. A node can only be in one list. O(1) adding and removal.
public class LinkedList<T> implements Iterable<T>
{
public LinkedNode<T> head = new LinkedNode<T>( this );
private int size = 0;
public final LinkedNode<T> add( T value )
{
return new LinkedNode<T>( value ).prepend( head );
}
@ClickerMonkey
ClickerMonkey / PointToCube.java
Last active December 29, 2015 03:08
Shader Fun
package com.axe.sandbox.gs;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.ARBBufferObject;
@ClickerMonkey
ClickerMonkey / SetOperations.java
Created December 11, 2013 12:45
Set operations
public class SetOperations
{
//===========================================================================
// A set is an immutable group of unique numbers ordered from smallest to
// largest. The values in the set must be ordered for all set operations to
// function properly, so don't manually change/re-order these!
//===========================================================================
class Set {
// The ordered set of numbers.
@ClickerMonkey
ClickerMonkey / Array.java
Created December 12, 2013 15:48
Array class (similar to ArrayList) but with reordering options and automatic downsizing.
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
public class Array<T> implements Iterable<T>
{
public T[] elements;
public int size;
import java.util.ArrayList;
//Saving Maze as Monochrome Bitmap
import java.io.*;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
// __ _ ___ _____ _____ ______ _ __ _____
// / | / | / |/ ___// ___/__ __/| | / // ___/
@ClickerMonkey
ClickerMonkey / DriveYaNuts.java
Last active August 29, 2015 13:57
Drive Ya Nuts Game Solver
public class DriveYaNuts
{
public static void main(String[] args) {
new DriveYaNuts();
}
/**
* BOARD POSITIONS
*
* _-1-_