Skip to content

Instantly share code, notes, and snippets.

KlausBrunner /
Created Oct 7, 2014
Elasticsearch boolean multifield silently ignored #6587
curl -XGET 'http://localhost:9200/'
# "status" : 200,
# "name" : "Spider-Man",
# "version" : {
# "number" : "1.3.2",
# "build_hash" : "dee175dbe2f254f3f26992f5d7591939aaefd12f",
# "build_timestamp" : "2014-08-13T14:29:30Z",
# "build_snapshot" : false,
# "lucene_version" : "4.9"
KlausBrunner /
Created Jun 1, 2015
Finding commits by SHA-1 hash on Github repos forked from a given root repo.
""" Finding commits by SHA-1 hash on Github. This is a simple
brute-force search for a specific usecase: you assume that the commit is
within all repos forked from a certain root repo within the past n days.
This may result in many calls to the GitHub API, which in turn may result
in GitHub's rate limiter kicking in and forcing you to take a break. You
have been warned.
Built with Python 3.4 and 0.9.4.
KlausBrunner / varnishncsa-request-time-vs-master.patch
Last active Oct 13, 2015
Add %D to log complete request time (beginning to end) in varnishncsa. Patches against varnish master & 3.0.3.
View varnishncsa-request-time-vs-master.patch
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 0b039b6..10664c7 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -39,6 +39,7 @@
* %l Client user ID as reported by identd (always "-")
* %u User ID if using HTTP authentication, or "-"
* %t Date and time of request
+ * %D time from beginning to completion of request
* %r Request line
KlausBrunner /
Last active Dec 10, 2015
Pull all the Mercurial repos listed in the TortoiseHg registry. Convenient if you're tracking lots of repositories.
#!/usr/bin/env python
Pull all the Mercurial repos listed in the TortoiseHg registry, in parallel.
Convenient if you're tracking lots of repositories.
from __future__ import print_function
import subprocess
KlausBrunner / asset_template.json
Last active Dec 11, 2015
Elasticsearch issue with phonetic plugin and index templates (stored in config). Tested with elasticsearch-analysis-phonetic 1.1.0 and 1.2.0 on both Linux and Windows on ES 0.19.12 and 0.20.2. Summary: it works without using a template, it works with a template added through the template API, but consistently fails with a template that is stored…
View asset_template.json
"asset_template": {
"template": "*",
"settings": {
"analysis": {
"filter": {
"metaphone_filter": {
"replace": false,
"encoder": "doublemetaphone",
"type": "phonetic"
KlausBrunner / web.xml
Created Dec 6, 2013
web.xml used with cditest, patched weld on jetty-9.1.[01]
View web.xml
<web-app xmlns=""
KlausBrunner / dump1.txt
Last active Dec 30, 2015
Cassandra 1.2.11 OOMs during relatively high read load, possibly around/in compaction?
View dump1.txt
ERROR [ReadStage:51] 2013-12-06 00:02:54,065 (line 191) Exception in thread Thread[ReadStage:51,5,main]
ERROR [ReadStage:51] 2013-12-06 00:02:54,065 (line 191) Exception in thread Thread[ReadStage:51,5,main]
java.lang.OutOfMemoryError: Java heap space
at org.apache.cassandra.utils.ByteBufferUtil.readWithLength(
at org.apache.cassandra.db.ColumnSerializer.deserializeColumnBody(
at org.apache.cassandra.db.OnDiskAtom$Serializer.deserializeFromSSTable(
at org.apache.cassandra.db.OnDiskAtom$Serializer.deserializeFromSSTable(
at org.apache.cassandra.db.columniterator.SimpleSliceReader.computeNext(
KlausBrunner / stacktraces.txt
Created Dec 13, 2013
postconstruct method on ServletListener called multiple times (on separate instances)
View stacktraces.txt
POST CONSTRUCT ON LISTENER CALLED test.ContextListener@1cadc928
at test.ContextListener.myPostConstructMethod(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
KlausBrunner /
Last active Feb 11, 2016
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:

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

KlausBrunner /
Last active Oct 3, 2016
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