Skip to content

Instantly share code, notes, and snippets.

View xkr47's full-sized avatar

Jonas Berlin xkr47

View GitHub Profile
@xkr47
xkr47 / NodeDetailFormatter.java
Last active August 29, 2015 13:57
Eclipse detail formatters for org.w3c.dom.*
// org.w3c.dom.Node
org.w3c.dom.bootstrap.DOMImplementationRegistry registry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance();
org.w3c.dom.ls.DOMImplementationLS impl = (org.w3c.dom.ls.DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0");
org.w3c.dom.ls.LSSerializer serializer = impl.createLSSerializer();
((org.w3c.dom.DOMConfiguration) serializer).setParameter("xml-declaration", Boolean.FALSE);
java.io.StringWriter out = new java.io.StringWriter();
org.w3c.dom.ls.LSOutput output = impl.createLSOutput();
output.setCharacterStream(out);
serializer.write(this, output);
@xkr47
xkr47 / ThrowableDetailFormatter.java
Created March 17, 2014 08:04
Eclipse detail formatter for java.lang.Throwable
java.io.StringWriter sw = new java.io.StringWriter();
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
printStackTrace(pw);
sw.toString();
@xkr47
xkr47 / update
Last active December 20, 2015 10:20
How to validate the files being pushed to a remote Git repository and leave repository untouched if validation failed - works with bare and non-bare repos
#!/bin/bash
# This file should be installed in the remote repository as:
# - <path-to-bare-repo.git>/hooks/update if you have a bare repository
# - <path-to-regular-repo>/.git/hooks/update if you have a regular repository
set -e
refname="$1"
oldrev="$2"
@xkr47
xkr47 / templates.xml
Created April 22, 2014 08:42
Java templates in Eclipse :: Window -> Preferences / Java > Editor > Templates
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java-members" deleted="false" description="Add logger decl" enabled="true" name="logger">${:importStatic(org.slf4j.Logger,org.slf4j.LoggerFactory.getLogger)}private static final Logger LOGGER = getLogger(${enclosing_type}.class);</template><template autoinsert="true" context="java" deleted="false" description="toString, hashCode, equals using reflection" enabled="true" name="the">${:importStatic(org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals,org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode,org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString)}
@Override
public boolean equals(final Object obj) {
return reflectionEquals(this, obj, true);
}
@Override
public int hashCode() {
return reflectionHashCode(this, true);
}
@xkr47
xkr47 / sar.conf
Last active September 7, 2019 15:06
Example logstash configuration for streaming/tailing sysstat "sar" command
input {
pipe {
tags => [ "sar", "loadavg" ]
command => "env LANG=C sar -q 5"
}
pipe {
tags => [ "sar", "cpu" ]
command => "env LANG=C sar -u 5"
}
}
@xkr47
xkr47 / DisableTomcatPersistentSessions.java
Created October 8, 2014 08:03
Disable persistent sessions in Tomcat embedded (which includes wicket sessions) (works at least with tomcat 7.0.54)
Tomcat tomcat = new Tomcat() {
@Override
public Host getHost() {
if (host == null) {
host = new StandardHost() {
@Override
public void addChild(final Container child) {
if (child instanceof StandardContext) {
setupContextWithNonpersistentSessionManager(child);
}
@xkr47
xkr47 / CookieDetailFormatter.java
Created October 8, 2014 11:35
Eclipse detail formatter for javax.servlet.http.Cookie
StringBuffer sb = new StringBuffer();
org.apache.tomcat.util.http.ServerCookie.appendCookieValue(sb, getVersion(), getName(), getValue(), getPath(), getDomain(), getComment(), getMaxAge(), getSecure(), isHttpOnly());
sb.toString();
@xkr47
xkr47 / curlum.sh
Last active August 29, 2015 14:12
Feed username/password to curl without temporary files and without showing in process list
# usage: curlum <username> <password> <curl args...>
curlum () {
user="$1"
pass="$2"
shift 2
curl --config /dev/fd/3 "$@" 3<<EOF
--user $user:$pass
EOF
}
@xkr47
xkr47 / gist:d0a1706f960c59648218
Last active April 24, 2018 04:29
Forward X DISPLAY over "sudo su - <user>", for example after ssh:ing to server
username=<user> ; echo -n "xauth add `xauth list :${DISPLAY#*:}`" | sudo su - $username ; sudo su - $username ; echo -n "xauth remove :${DISPLAY#*:}" | sudo su - $username
@xkr47
xkr47 / cvsignore2git.sh
Last active December 8, 2023 09:58
cvsignore -> gitignore converter
#!/bin/sh
if [ ! -d .git ]; then
echo ERROR: Please run this in the root of the git repository
exit 1
fi
cat > .gitignore <<'EOF'
# CVS global ignores
RCS