Skip to content

Instantly share code, notes, and snippets.

@digulla
digulla / PageRegion
Last active January 25, 2017 09:32
Support code to write unit tests that validate PDF documents
import java.awt.geom.Rectangle2D;
import org.apache.pdfbox.text.PDFTextStripperByArea;
public class PageRegion {
private String name;
private Rectangle2D rect;
// Coordinates are in the order in which the Apache PDF-Box Debugger displays them
@digulla
digulla / JettyWebFragmentHelper.java
Created June 9, 2017 08:32
Jetty helper to manually load web-fragment.xml from JARs and class folders on the classpath.
/**
* 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 -> {
@digulla
digulla / StandaloneServletContextUriLocator2.java
Last active October 17, 2017 08:12
Variant of StandaloneServletContextUriLocator from wro4j which can also load from web resources from the classpath.
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;
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 / ConfigException.groovy
Created March 14, 2019 09:09
Code for a nested config that can validate path and type errors
class ConfigException extends RuntimeException {
ConfigException(String message) {
super(message)
}
ConfigException(String message, Throwable cause) {
super(message, cause)
}
}
#!/bin/bash
set -o pipefail
archive="$1"
fromImage="$2"
outputName=$(basename "$archive" ".tar.gz")-partial.tar
echo "Result will be in ${outputName}.gz"