Skip to content

Instantly share code, notes, and snippets.

@timmolderez
timmolderez / ArithmeticParser.java
Last active December 7, 2016 23:37
Design patterns exercise: composite, iterator, visitor
package be.ac.vub.patterns;
import java.util.Stack;
public class ArithmeticParser {
public enum Parentheses { LEFT, RIGHT }
public enum BinaryOperator {
ADD('+', 1) {
public Double eval(Double leftValue, Double rightValue) { return leftValue + rightValue; }
@timmolderez
timmolderez / pom.xml
Created November 30, 2016 23:53
Test code coverage in GitLab CI
To compute test code coverage, whenever someone pushes to the git repository:
1 - First add the following two plugins to the <plugins> section of your pom.xml.
The Surefire plugin executes unit tests, and the Jacoco plugin will compute test coverage:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
@timmolderez
timmolderez / Clock.java
Created November 17, 2016 10:19
Design patterns exercise
import java.text.SimpleDateFormat;
import java.util.Date;
public class Clock implements Runnable {
public static final int TIME_24 = 0;
public static final int TIME_US = 1;
public static final int TIME_UNIX = 2;
private int displayType = TIME_24;
public static void main(String[] args) {
@timmolderez
timmolderez / pom.xml
Last active May 2, 2024 05:24
Adding dependencies to local .jar files in pom.xml
If you'd like to use a .jar file in your project, but it's not available in any Maven repository,
you can get around this by creating your own local repository. This is done as follows:
1 - To configure the local repository, add the following section to your pom.xml (inside the <project> tag):
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
@timmolderez
timmolderez / SwingTest.java
Created November 4, 2016 07:52
Basic framework to perform Swing tests for the Pixelitor application
package pixelitor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
@timmolderez
timmolderez / Main.java
Created October 12, 2016 22:03
Simple Swing application
package be.vub;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;
@RunWith(Theories.class)
public class AdditionWithTheoriesTest {
package test;
public class Matrix {
public static double[][] random(int m, int n) {
double[][] C = new double[m][n];
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
C[i][j] = Math.random();
return C;
}
@timmolderez
timmolderez / gist:5209524
Last active December 15, 2015 05:29
Alternate version of this xkcd comic: http://xkcd.com/1188
/**
* Alternate version of this xkcd comic: http://xkcd.com/1188
*
* My inner nitpicker was bugged by the fact that the comic isn't actually
* using the throw-catch exception mechanism to throw the ball over to the
* target, which I thought was the whole point.
* What actually happens is this: the parent throws the ball, catches it
* himself and then just passes it to the child (as a parameter)... which looks
* kinda silly when picturing it :) So I had to rewrite the thing such that
* it's a proper game of play catch..