Skip to content

Instantly share code, notes, and snippets.

View mnuessler's full-sized avatar
💻
Open to freelance work

Matthias Nüßler mnuessler

💻
Open to freelance work
View GitHub Profile
@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>
@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 / 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.
*
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();
#
# 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
#
@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
@mnuessler
mnuessler / fingerprints.sh
Created March 10, 2016 11:56
Host SSH key fingerprints for all key ciphers
#!/bin/bash
# Not my own creation, copied from:
# http://superuser.com/questions/929566/sha256-ssh-fingerprint-given-by-the-client-but-only-md5-fingerprint-known-for-se
# standard sshd config path
SSHD_CONFIG=/etc/ssh/sshd_config
# helper functions
function tablize {
@mnuessler
mnuessler / locales.sh
Created June 21, 2016 13:02
Fixes warning "Setting locale failed." on Debian
# Fix this warning on Debian/Ubuntu:
# perl: warning: Setting locale failed.
# perl: warning: Please check that your locale settings:
# LANGUAGE = (unset),
# LC_ALL = (unset),
# LANG = "en_US.utf8"
# are supported and installed on your system.
# perl: warning: Falling back to the standard locale ("C").
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
@mnuessler
mnuessler / log4j.properties
Last active June 29, 2016 07:12
Logging configuration for Gerrit that writes everything nach stdout.
log4j.rootLogger=INFO, stdout
log4j.logger.sshd_log=INFO, sshd_log
log4j.logger.httpd_log=INFO, httpd_log
log4j.logger.gc_log=INFO, gc_log
log4j.logger.replication_log=INFO, replication_log
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.apConversionPattern=[%d] %-5p %c %x: %m%n
@mnuessler
mnuessler / twoline_prompt.sh
Created October 7, 2017 12:29 — forked from mkottman/twoline_prompt.sh
A two-line colored Bash prompt (PS1) with Git branch and a line decoration which adjusts automatically to the width of the terminal. Recognizes SVN, Git and Fossil version control systems and shows the current branch/revision.
# A two-line colored Bash prompt (PS1) with Git branch and a line decoration
# which adjusts automatically to the width of the terminal.
# Recognizes and shows Git, SVN and Fossil branch/revision.
# Screenshot: http://img194.imageshack.us/img194/2154/twolineprompt.png
# Michal Kottman, 2012
RESET="\[\033[0m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[01;32m\]"
BLUE="\[\033[01;34m\]"