Skip to content

Instantly share code, notes, and snippets.

@josefbetancourt
josefbetancourt / ClasspathTestScanner
Last active Aug 29, 2015
Simple method to search Java classpath to find @test annotated JUnit tests
View ClasspathTestScanner
/**
* Get all test classes starting from a base package path.
* <p>
* Example use:
* <pre>
* UnitTestScanner scanner = new UnitTestScanner();
* List<Class<?>> list = scanner.getTestClasses("com.octodecillion.test");
* </pre>
* @param basePackage package where search will start
* @param debug if true output more info
View HexDump.groovy
package com.octodecillion.util
import static java.lang.Character.*
/**
* Simple ASCII hex dump of file.
* <p>
* Example output:<br>
* <pre>
* OFFSET 0 1 2 3 4 5 6 7 8 9 a b c d e f | ASCII
@josefbetancourt
josefbetancourt / INIX-example.inix
Last active Dec 29, 2015
Inix file reader source code to accompany blog post "Groovy implementation of INIX file format"
View INIX-example.inix
# Example very simple data file
#
[>root]
one
two
three
[<root]
[>demo1/compile]
x,y,z
[<demo1/compile]
@josefbetancourt
josefbetancourt / GoGenerator.groovy
Created Oct 15, 2013
Code for blog post "Change dir batch generator using Groovy" on http://octodecillion.com
View GoGenerator.groovy
/**
* GoGenerator.groovy
* Copyright 2010 Josef Betancourt 20100312-17:47
*/
/*@Grapes([
@Grab(group='ch.qos.logback', module='logback-core', version='0.9.18'),
@Grab(group='ch.qos.logback', module='logback-classic', version='0.9.18'),
@Grab(group='org.slf4j', module='slf4j-api', version='1.5.10')])
@josefbetancourt
josefbetancourt / Gather.groovy
Last active Dec 23, 2015
Code to accompany "Parsing files using Groovy closures" on my blog.
View Gather.groovy
package com.octodecillion
import java.nio.file.Files;
/**
* Simple folder walker and file parser.
* <p>
* Dev with Groovy 2.1.6, Java 7, Eclipse 4.3
*
* @author jbetancourt
@josefbetancourt
josefbetancourt / SvnOutputTransform.java
Last active Dec 15, 2015
Transform SVN log diff using Java XPath example for blog post http://octodecillion.com/blog/svn-report-java-xpath/
View SvnOutputTransform.java
/**
*
*/
package com.octodecillion.utils;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
@josefbetancourt
josefbetancourt / GraphSort.java
Last active Dec 10, 2015
Source code for blog post "List sorting using topological ordering of a digraph" http://octodecillion.com/blog/sort-using-digraph/
View GraphSort.java
package com.octodecillion.sort;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
@josefbetancourt
josefbetancourt / Vsdf.groovy
Last active Dec 9, 2015
Groovy source code from blog post "A very simple data file metaformat" at http://octodecillion.com/blog/very-simple-data-file-format/
View Vsdf.groovy
package com.octodecillion.inix
import java.util.regex.Pattern
import groovy.transform.TypeChecked
import java.util.regex.Matcher
/**
*
*
* @author Josef Betancourt
@josefbetancourt
josefbetancourt / JarInfo.java
Created Dec 15, 2012
Source code from blog post "Java Generics Example: Jar Manifest" at [http://octodecillion.com/blog/java-generics-manifest/]
View JarInfo.java
/**
*
*/
package com.octodecillion.utils;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@josefbetancourt
josefbetancourt / InvokeCounter.java
Last active Oct 13, 2015
Behavior counters for improved JUnit tests
View InvokeCounter.java
package com.octodecillion.junit;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
/**