Skip to content

Instantly share code, notes, and snippets.

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
public class RegexMatcher extends BaseMatcher {
private final String regex;
public RegexMatcher(String regex){
this.regex = regex;
}
@jashatton
jashatton / build.gradle
Created August 2, 2012 14:05
A build.gradle script that reads Maven dependencies using XmlSlurper and applies them to the gradle dependencies.
apply plugin: 'java'
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
@jashatton
jashatton / PngToDataUrl.java
Created December 23, 2013 18:15
A class that can create a circle as a png and reencode it as a dataurl, Base64 encoded, image. I used this to create markers on Google Maps in GWT.
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
@jashatton
jashatton / gist:10951000
Created April 17, 2014 03:30
Processing Animation Example
float yPos = 0.0;
float xPos = 0.0;
float xDirection = 1.0;
float yDirection = 1.0;
void setup() {
size(800, 600);
background(0);
}
@jashatton
jashatton / SortSomeValues.java
Created November 6, 2014 15:29
Interview question template for sorting values from an array
import java.util.Arrays;
import java.util.List;
public class SortSomeValues {
public static void main(String[] args) {
int[] values = {75, 100, 30, 50, 2, 144, 303, 0, 402, 0.0, 83};
}
}
@jashatton
jashatton / GetAnAverageWithBadTemperaturesTemplate.java
Created November 6, 2014 15:46
Average temperature removing bad temperatures
public class GetAnAverageWithBadTemperaturesTemplate {
public static void main(String[] args) {
int[] temperatureReadings = { 1, 34, 45, 30, 46, 40, 45, 500, 40, 50,
55, 56, 62, 2, 200, 40, 55, 49, 60, 59,
70, 68, 71, 90, 60, 70, 65, 66, 72, 68, 81 };
}
}