Skip to content

Instantly share code, notes, and snippets.

View culmat's full-sized avatar

Matthias Cullmann culmat

View GitHub Profile
@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) {
@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 / 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;
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 / 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.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class JarFileLoader extends URLClassLoader {
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.util.function.Consumer;
import java.util.function.Function;
public class Consumers {
/**
* <pre>
package common;
/**
* <blockquote>
* <pre>
* Map<String, Integer> myMap = map("a", 1).with("b", 2);
* </pre>
* </blockquote>
*
* The first tuple determines the map type, so cast as appropriate:
* <blockquote>
@culmat
culmat / ImportTLSCert.java
Last active March 25, 2024 16:58
Imports the (selfsigned) untrusted certificated from an HTTPS server or proxy server into a (current JREs) cacerts file
package com.baloise.proxy;
import static java.io.File.separator;
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.util.Arrays.asList;
import static java.util.regex.Pattern.quote;
import static java.util.stream.Collectors.joining;
import java.io.File;
import java.io.IOException;