Skip to content

Instantly share code, notes, and snippets.

View culmat's full-sized avatar

Matthias Cullmann culmat

View GitHub Profile
package common;
import java.util.function.Consumer;
import java.util.function.Function;
public class Consumers {
/**
* <pre>
package common;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class JDBCDebug {
package common;
import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class JarFileLoader extends URLClassLoader {
@culmat
culmat / DuckType.java
Last active February 24, 2017 10:37
if it walks like a duck and talk like a duck ...
package common;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class DuckType implements InvocationHandler {
public static class Let {
private Object object;
package common;
import java.util.Base64;
import java.util.Random;
public class Crypto {
public static String base64encode(String text) {
return Base64.getEncoder().encodeToString(text.getBytes());
}
@culmat
culmat / Truth.java
Last active August 29, 2015 14:19
Truth
package common;
import static java.util.Arrays.asList;
import java.awt.Desktop.Action;
import java.awt.Point;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@culmat
culmat / Format.java
Last active June 16, 2017 08:00
Format
package common;
public class Format {
private static final String[] BYTE_UNITS = new String[] { "b", "Kb", "Mb", "Gb" };
private static final int[] BYTE_STEPS = new int[] { 1024, 1024, 1024, 1024 };
private static final String[] TIME_UNITS = new String[] { "msec", "sec", "min", "h", "day", "week", "year" };
private static final int[] TIME_STEPS = new int[] { 1000, 60, 60, 24, 7, 52, 100 };
public static String format(String[] unit, int[] step, double value) {
int i = 0;
@culmat
culmat / FactoryHashMap.java
Last active November 27, 2015 10:13
FactoryHashMap
package common;
import java.util.HashMap;
import java.util.function.Function;
/**
* How many times have you written code like this
* <blockquote><pre>
* List&lt;Integer&gt; value = map.get(key);
* if(value == null) {