Skip to content

Instantly share code, notes, and snippets.

View andytill's full-sized avatar

Andy Till andytill

View GitHub Profile
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
public class FXMLLoadingModule extends AbstractModule {
private final FXMLLoadingScope fxmlLoadingScope;
public FXMLLoadingModule() {
fxmlLoadingScope = new FXMLLoadingScope();
}
package projmon.guice;
import java.util.ArrayList;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
public class FXMLLoadingScope extends EnterableScope {
@Target({ TYPE, METHOD }) @Retention(RUNTIME) @ScopeAnnotation
public @interface FXMLLoadingScoped {
}
@andytill
andytill / JavaFXThreadingRule.java
Created October 4, 2012 19:42
A Junit @rule for running tests on the JavaFX thread
import java.util.concurrent.CountDownLatch;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@andytill
andytill / CompatibleImageBenchMark.java
Created November 2, 2012 10:08
A mini benchmark to test if Java compatible images are rendered faster than images loaded in the default manner, results printed on the command line.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
@andytill
andytill / MethodHandleTest.java
Created November 2, 2012 10:11
A benchmark for testing method handle performance.
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class MethodHandleTest
{
private static final String METHOD_NAME = "increment";
@andytill
andytill / csv.erl
Last active May 26, 2016 22:22
Erlang state machine for parsing a CSV file
%% @author atill
%%
%% @doc
%% CSV parsing module. Parsed CSV will be processed and converted
%% into a list containing the separated values, lines are separated
%% by the newline atom.
-module(csv).
-import(lists, [reverse/1]).
@andytill
andytill / HierarchyTreeCell.java
Created November 4, 2012 00:44
A JavaFX TreeCell implementation with drag and drop.
package projmon.hierarchical;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.effect.InnerShadow;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
public class Math {
public static boolean isPrime(final long number) {
if (number == 2)
return true;
if (number < 2)
return false;
if(number % 2 == 0)
return false;
long maxCheck = (long) Math.sqrt(number);
@andytill
andytill / web.rb
Created November 18, 2012 21:16
A Sinatra proxy to be used over a neo4j ReST API
# web proxy for a neo4j database, using Heroku but could be easily modified for anything else
# this code is a modified version of the code found here https://github.com/akollegger/nosql-now/blob/master/web.rb
# the main changes are...
# - authentication required for modification, although viewing is allowed without authentication (auth can be added by calling protected! in the get method)
# - the domain returned in the data is replaced with the proxy domain instead of being removed which was causing errors in the java jersey library
# - modified post routing, this wasn't catching all POST requests
require 'sinatra'
require 'rest-client'
require 'json'