Skip to content

Instantly share code, notes, and snippets.

@snarkbait
snarkbait / DiGraph.java
Created June 2, 2015 06:10
Generic Directed, Weighted Graph with Dijkstra's Shortest Path
/* Generic Directed Weighted Graph with Dijkstra's Shortest Path Algorithm
* by /u/Philboyd_Studge
* for /r/javaexamples
*/
import java.util.List;
import java.util.Queue;
import java.util.PriorityQueue;
import java.util.Deque;
import java.util.LinkedList;
@snarkbait
snarkbait / BinaryHeap.java
Last active December 10, 2022 22:45
Generic Min/Max Binary Heap
/* Generic Min/Max Binary Heap
* for /r/javaexamples
*
*/
import java.util.Arrays;
@SuppressWarnings("unchecked")
/**
* Creates an array-based binary heap. Defaults to 'min' (Priority Queue)
@snarkbait
snarkbait / BinaryTreeKV.java
Created May 22, 2015 06:38
Generic Self-Balancing Key-Value Binary Search Tree for /r/javaexamples
/* Generic Self-Balancing Key-Value Binary Search Tree
for /r/javaexamples
by /u/Philboyd_Studge
*/
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
@SuppressWarnings("unchecked")
@snarkbait
snarkbait / DynamicArray.java
Created March 7, 2016 21:56
Dynamic Array example
import java.util.Arrays;
import java.util.Iterator;
import java.util.RandomAccess;
/**
* Dynamic Array class (based on java.util.ArrayList)
* for /r/JavaExamples - for tutorial purposes -
* @author /u/Philboyd_Studge on 11/18/2015.
*/
@snarkbait
snarkbait / BitStream.java
Created August 9, 2015 00:45
Huffman Tree example
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@snarkbait
snarkbait / Inventory.java
Last active March 31, 2021 17:11
InventoryGUI SQlite Example for /r/javaexamples
/* Inventory class
* for /r/javaexamples
* by /u/Philboyd_Studge
*
*/
package philboyd.studge;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Random;
@snarkbait
snarkbait / Direction.java
Created November 29, 2017 08:07
Direction enum class - Advent of Code helper
package util;
/**
* @author /u/Philboyd_Studge on 12/26/2016.
*
* This enum set is for simplifying movement on a 2d integer grid
* Assuming the Y axis is -up(north) and +down(south),
* and X axis is -right(west) and +left(east)
*/
public enum Direction {
@snarkbait
snarkbait / AdventOfCode.java
Created December 16, 2017 07:29
Advent of Code 2017 - Abstract Challenge Class, Loader, Runner, and more
package util;
import java.util.List;
public abstract class AdventOfCode {
protected List<String> input;
public AdventOfCode(List<String> input) {
this.input = input;
@snarkbait
snarkbait / FVController.java
Created March 27, 2017 21:46
JavaFX Example - Future Value
package fvcalc;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import logic.FVLogic;
import logic.FVLogic.CompoundType;
@snarkbait
snarkbait / Day25.java
Created December 25, 2017 06:03
Advent of Code 2017 Day 25
package Advent2017;
import util.AdventOfCode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class Day25 extends AdventOfCode {