Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Berlin xkr47

View GitHub Profile
@xkr47
xkr47 / git-mvs
Created Feb 24, 2014
Rename all *.sh files to *.pl: git mvs 's/\.sh$/.pl/' *.sh
View git-mvs
#!/bin/bash
if [ $# -lt 1 ]; then
echo usage: "$0 <perl> [<file1> ...]"
exit 1
fi
sed="$1"
shift
@xkr47
xkr47 / CustomWebdriverDisplay.java
Created Mar 14, 2014
How to set up webdriver to optionally use alternative DISPLAY setting for browser
View CustomWebdriverDisplay.java
FirefoxBinary firefox = new FirefoxBinary();
// allow user to specify which DISPLAY to use if running e.g. Xephyr
String display = System.getProperty("firefoxDisplay");
if (display != null) {
firefox.setEnvironmentProperty("DISPLAY", display);
}
WebDriver driver = new FirefoxDriver(firefox, null);
@xkr47
xkr47 / NodeDetailFormatter.java
Last active Aug 29, 2015
Eclipse detail formatters for org.w3c.dom.*
View NodeDetailFormatter.java
// 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 Mar 17, 2014
Eclipse detail formatter for java.lang.Throwable
View ThrowableDetailFormatter.java
java.io.StringWriter sw = new java.io.StringWriter();
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
printStackTrace(pw);
sw.toString();
@xkr47
xkr47 / templates.xml
Created Apr 22, 2014
Java templates in Eclipse :: Window -> Preferences / Java > Editor > Templates
View templates.xml
<?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 / CookieDetailFormatter.java
Created Oct 8, 2014
Eclipse detail formatter for javax.servlet.http.Cookie
View CookieDetailFormatter.java
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 / DisableTomcatPersistentSessions.java
Created Oct 8, 2014
Disable persistent sessions in Tomcat embedded (which includes wicket sessions) (works at least with tomcat 7.0.54)
View DisableTomcatPersistentSessions.java
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 / curlum.sh
Last active Aug 29, 2015
Feed username/password to curl without temporary files and without showing in process list
View curlum.sh
# 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 / jolla-usb-power-states.sh
Last active Aug 29, 2015
Jolla phone: Different usb power states
View jolla-usb-power-states.sh
# NOTE: In order to change state, you need to run all three commands for the wanted state
# in given order to get the desired effect
# Charge battery, and use usb power to power phone (default state after powering up the phone)
chmod u+w /sys/class/power_supply/usb/charger_disable
echo 0 > /sys/module/pm8921_charger/parameters/disabled
echo 0 > /sys/class/power_supply/usb/charger_disable
# don't charge battery, but use usb power to power phone
chmod u+w /sys/class/power_supply/usb/charger_disable
@xkr47
xkr47 / myapp.cpp
Last active Aug 29, 2015 — forked from kimmoli/myclass.cpp
Disable SailfishOS app cover animation when cover is not visible
View myapp.cpp
...
#include "myclass.h"
...
int main(int argc, char *argv[])
{
qmlRegisterType<myclass>("harbour.myapp.myclass", 1, 0, "myclass");
...
}
You can’t perform that action at this time.