Skip to content

Instantly share code, notes, and snippets.

View partial-docker-image.sh
#!/bin/bash
set -o pipefail
archive="$1"
fromImage="$2"
outputName=$(basename "$archive" ".tar.gz")-partial.tar
echo "Result will be in ${outputName}.gz"
@digulla
digulla / DangerousPathChecker.java
Last active Jul 12, 2019
How to check whether a file is on a network share with Java
View DangerousPathChecker.java
/** Copyleft (C) 2016 by Aaron Digulla. Use as you wish. This copyright notice can be removed. */
package bug507401;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
@digulla
digulla / DefaultLocaleRule.java
Last active May 23, 2019
JUnit 4 Rule to run individual tests with a different default locale
View DefaultLocaleRule.java
import java.util.Locale;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
public class DefaultLocaleRule extends TestWatcher {
private Locale originalDefault;
private Locale currentDefault;
public DefaultLocaleRule() {
@digulla
digulla / AnnotatedBeanLocator.java
Last active Mar 20, 2019
Locate beans in an ApplicationContext by annotation on the method which defines the bean.
View AnnotatedBeanLocator.java
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.type.StandardMethodMetadata;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
@digulla
digulla / ConfigException.groovy
Created Mar 14, 2019
Code for a nested config that can validate path and type errors
View ConfigException.groovy
class ConfigException extends RuntimeException {
ConfigException(String message) {
super(message)
}
ConfigException(String message, Throwable cause) {
super(message, cause)
}
}
View Steam System Information.log
Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Desktop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
CPU Family: 0x6
@digulla
digulla / H2TransactionTest.java
Last active Aug 22, 2018
Test case for multi-threaded access to an H2 database
View H2TransactionTest.java
package de.pdark.h2.txtest;
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Test;
public class H2TransactionTest {
@digulla
digulla / Default (Linux).sublime-keymap
Last active Aug 21, 2018
Eclipse keyboard mapping for Sublime Text 2+3, based on https://gist.github.com/thbkrkr/3194275
View Default (Linux).sublime-keymap
// Put this in .../Packages/User/Default (**YOUR_OS_HERE**).sublime-keymap
[
// Eclipse keyboard mapping for Sublime Text 2+3, based on https://gist.github.com/thbkrkr/3194275
{ "keys": ["f12"], "command": "htmlprettify"},
{ "keys": ["f1"], "command": "fold" },
{ "keys": ["f2"], "command": "unfold" },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
{ "keys": ["ctrl+space"], "command": "auto_complete" },
{ "keys": ["ctrl+space"], "command": "replace_completion_with_auto_complete", "context":
@digulla
digulla / StandaloneServletContextUriLocator2.java
Last active Oct 17, 2017
Variant of StandaloneServletContextUriLocator from wro4j which can also load from web resources from the classpath.
View StandaloneServletContextUriLocator2.java
package ch.swissquant.gkb.ui.wro;
import static org.apache.commons.lang3.Validate.notNull;
import static org.apache.commons.lang3.Validate.validState;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@digulla
digulla / JettyWebFragmentHelper.java
Created Jun 9, 2017
Jetty helper to manually load web-fragment.xml from JARs and class folders on the classpath.
View JettyWebFragmentHelper.java
/**
* Manually load <code>web-fragment.xml</code> from JARs and class folders on the classpath.
*
* <p>Jetty can only find them automatically if the fragment is in a JAR in <code>WEB-INF/lib/</code>.
*/
protected void loadWebFragments(WebAppContext ctx) {
Map<Resource, Resource> frags = getOrCreateFragmentResources(ctx);
try {
ArrayList<URL> urls = Collections.list(getClass().getClassLoader().getResources("META-INF/web-fragment.xml"));
urls.forEach(url -> {