Skip to content

Instantly share code, notes, and snippets.

View mnuessler's full-sized avatar

Matthias Nüßler mnuessler

View GitHub Profile
@mnuessler
mnuessler / docker-cleanup.sh
Last active August 29, 2015 14:25
Yet another docker cleanup script. Deletes stopped docker containers and untagged images, prints information about freed disk space.
#!/bin/bash
#
# Cleans up docker files:
# - Deletes untagged docker images
# - Deletes stopped docker containers
# - Deletes long-running docker containers (use with care!)
set -e
if [ $# -eq 0 ]; then
#
# This config file is a combination of ideas from:
# http://www.37signals.com/svn/posts/1073-nuts-bolts-haproxy
# http://www.igvita.com/2008/05/13/load-balancing-qos-with-haproxy/
# http://wiki.railsmachine.com/HAProxy
# http://elwoodicious.com/2008/07/15/nginx-haproxy-thin-fastcgi-php5-load-balanced-rails-with-php-support/
# http://upstream-berlin.com/2008/01/09/using-haproxy-with-multiple-backends-aka-content-switching/
# http://wiki.railsmachine.com/HAProxy
# http://gist.github.com/raw/25482/d39fb332edf977602c183194a1cf5e9a0b5264f9
#
public class XmlIndent {
/*
* Format XML with indentation
*/
private static String prettyFormat(InputStream input, int indent) {
try {
Source xmlInput = new StreamSource(input);
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
@mnuessler
mnuessler / Status.java
Last active December 25, 2015 08:59
A Java example of using a hash map for fast lookup of enum instances by a property.
import java.util.Map;
import com.google.common.collect.Maps;
/*
* An example enumeration using a hash map to lookup an enumeration instance per ID.
*
* A lookup in a hash map is way faster than iterating for the enum instances until you
* find the matching one.
*
@mnuessler
mnuessler / DomUtil.java
Created December 30, 2012 12:38
Snippets for working with XML in Java
public final class DomUtil {
private DomUtil() {
// prevent instantiation
}
public static Document stringToDocument(String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
InputSource input = new InputSource(new StringReader(xml));
@mnuessler
mnuessler / template-java-after.xml
Created October 20, 2012 21:42
Templates for the Eclipse IDE
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java-members" deleted="false" description="tear down after test" enabled="true" name="after">@${afterType:newType(org.junit.After)}
public void tearDown() throws Exception {
${cursor}
}</template></templates>