Skip to content

Instantly share code, notes, and snippets.

@josefbetancourt
josefbetancourt / ClasspathTestScanner
Last active August 29, 2015 14:24
Simple method to search Java classpath to find @test annotated JUnit tests
/**
* 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
@josefbetancourt
josefbetancourt / HexDump.groovy
Last active September 13, 2016 15:25
Groovy Hex Dump
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 December 29, 2015 17:09
Inix file reader source code to accompany blog post "Groovy implementation of INIX file format"
# Example very simple data file
#
[>root]
one
two
three
[<root]
[>demo1/compile]
x,y,z
[<demo1/compile]
@josefbetancourt
josefbetancourt / GoGenerator.groovy
Created October 15, 2013 01:20
Code for blog post "Change dir batch generator using Groovy" on http://octodecillion.com
/**
* 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 December 23, 2015 18:59
Code to accompany "Parsing files using Groovy closures" on my blog.
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 December 15, 2015 02:39
Transform SVN log diff using Java XPath example for blog post http://octodecillion.com/blog/svn-report-java-xpath/
/**
*
*/
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 December 10, 2015 12:18
Source code for blog post "List sorting using topological ordering of a digraph" http://octodecillion.com/blog/sort-using-digraph/
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 December 9, 2015 22:18
Groovy source code from blog post "A very simple data file metaformat" at http://octodecillion.com/blog/very-simple-data-file-format/
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 December 15, 2012 00:18
Source code from blog post "Java Generics Example: Jar Manifest" at [http://octodecillion.com/blog/java-generics-manifest/]
/**
*
*/
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 October 13, 2015 11:48
Behavior counters for improved JUnit tests
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;
/**