Skip to content

Instantly share code, notes, and snippets.

View klausbrunner's full-sized avatar

Klaus Brunner klausbrunner

View GitHub Profile
@klausbrunner
klausbrunner / hexdump.java
Created December 10, 2019 09:52
Java byte array to hexdump. Format similar to default of hexdump(1).
static String hexDump(byte[] bytes) {
Formatter format = new Formatter(new StringBuilder());
for (int j = 0; j < bytes.length; j++) {
if (j % 16 == 0) {
format.format((j > 0 ? "\n" : "") + "%08X ", j);
}
format.format("%02X ", bytes[j]);
}
return format.toString();
}
@klausbrunner
klausbrunner / parent-from-existing.py
Created August 12, 2019 04:43
Generate a basic parent POM from all subfolders that contain Maven projects.
#!/usr/bin/env python3
import os
import argparse
parser = argparse.ArgumentParser(description='Generate a Maven parent pom for existing Maven projects in a folder.')
parser.add_argument('root', default='.', nargs='?',
help='root (parent) folder')
parser.add_argument('--group', default='localhost',
help='groupId for parent POM')
@klausbrunner
klausbrunner / hls-distances.html
Created March 21, 2019 17:36
Trivial example to calculate route distances from a fixed point to location(s) specified as user input, using HERE Location Services.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
</head>
@klausbrunner
klausbrunner / gerrit-ssh.py
Created December 10, 2015 18:11
Accessing the gerrit SSH interface using Python (via ssh config entry)
#!/usr/bin/env python
import paramiko
import sys
import os
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
config = paramiko.SSHConfig()
@klausbrunner
klausbrunner / wars-dist.xml
Created December 20, 2012 09:42
Maven assembly plugin descriptor to bundle all WAR dependencies into a zip file, including local resource files. This is useful when you don't use EARs, but still want to package several web applications into one big archive, plus any additional stuff (e.g. configuration files) needed for deployment.
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<!-- A Maven assembly plugin descriptor to bundle all WAR dependencies into a zip file, including local
resource files. This is useful when you don't use EARs, but still want to package several web applications
into one big archive, plus any additional stuff (e.g. configuration files) needed for deployment. -->
<id>dist</id>
<formats>
<format>zip</format>
@klausbrunner
klausbrunner / Unzipper.java
Last active September 2, 2018 14:00
Extracts files and directories of a standard zip file to a destination directory. Requires at least Java 7.
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import static java.nio.file.Files.*;
/**
* Extracts files and directories of a standard zip file to a destination directory. Requires at least Java 7.
*/
@klausbrunner
klausbrunner / manifest_growth.py
Last active October 3, 2016 08:07
Track a repo manifest's project count over time using GitPython. Prints simple "datetime count" table.
import os
from git import Repo
import datetime as dt
import xml.etree.ElementTree as ET
repo = Repo('/home/klaus/stats/manifests')
target_file = 'manifest.xml'
assert not repo.bare
@klausbrunner
klausbrunner / 1jetty-weld-howto.md
Last active February 11, 2016 16:17
Using Weld 2.x as a CDI 1.1 implementation on Jetty 9.1, and Jersey 2.x for JAX-RS 2.0 on top of that

Servlets with CDI

  • get latest Jetty 9.1 archive and extract somewhere (I'll assume the Jetty root is called "jetty")
  • in jetty/lib, create a folder called "weld" and download the weld-servlet and weld-servlet-core JARs into it. For injection in listeners to work, version should be 2.2.0.Beta1 or later.
  • in jetty/modules, create a weld.mod as in this gist
  • in jetty/start.ini, add a single line containing "--module=weld" to initialise Weld

In most cases, that should be it and you can deploy any compliant CDI application, even without a web.xml. In some cases though you may need to add the old-fashioned filter entry to the web.xml. See also: weld/core#465

Servlets with CDI and JAX-RS 2.0 (using Jersey)

@klausbrunner
klausbrunner / stacktraces.txt
Created December 13, 2013 09:41
postconstruct method on ServletListener called multiple times (on separate instances)
POST CONSTRUCT ON LISTENER CALLED test.ContextListener@1cadc928
java.lang.Throwable
at test.ContextListener.myPostConstructMethod(ContextListener.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.plus.annotation.LifeCycleCallback.callback(LifeCycleCallback.java:117)
at org.eclipse.jetty.plus.annotation.PostConstructCallback.callback(PostConstructCallback.java:57)
at org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection.callPostConstructCallback(LifeCycleCallbackCollection.java:115)
@klausbrunner
klausbrunner / dump1.txt
Last active December 30, 2015 11:09
Cassandra 1.2.11 OOMs during relatively high read load, possibly around/in compaction?
ERROR [ReadStage:51] 2013-12-06 00:02:54,065 CassandraDaemon.java (line 191) Exception in thread Thread[ReadStage:51,5,main]
ERROR [ReadStage:51] 2013-12-06 00:02:54,065 CassandraDaemon.java (line 191) Exception in thread Thread[ReadStage:51,5,main]
java.lang.OutOfMemoryError: Java heap space
at org.apache.cassandra.io.util.RandomAccessReader.readBytes(RandomAccessReader.java:376)
at org.apache.cassandra.utils.ByteBufferUtil.read(ByteBufferUtil.java:392)
at org.apache.cassandra.utils.ByteBufferUtil.readWithLength(ByteBufferUtil.java:355)
at org.apache.cassandra.db.ColumnSerializer.deserializeColumnBody(ColumnSerializer.java:108)
at org.apache.cassandra.db.OnDiskAtom$Serializer.deserializeFromSSTable(OnDiskAtom.java:92)
at org.apache.cassandra.db.OnDiskAtom$Serializer.deserializeFromSSTable(OnDiskAtom.java:73)
at org.apache.cassandra.db.columniterator.SimpleSliceReader.computeNext(SimpleSliceReader.java:106)