Skip to content

Instantly share code, notes, and snippets.

View klausbrunner's full-sized avatar

Klaus Brunner klausbrunner

  • Berlin/Munich/Vienna
View GitHub Profile
@klausbrunner
klausbrunner / SimpleFuture.java
Created November 19, 2012 11:34
A very simple implementation of the Java Future interface, for passing a single value to some waiting thread. Uses a CountdownLatch to ensure thread safety and provide blocking-with-timeout functionality required by Future. Cancellation isn't supported.
public final class ResultFuture implements Future<Result> {
private final CountDownLatch latch = new CountDownLatch(1);
private Result value;
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
@klausbrunner
klausbrunner / counters.cql
Created November 20, 2012 14:25
creating and using a Cassandra counter column in CQL
-- creating and using a Cassandra counter column in CQL
-- NOTE: this is CQL 2.0 syntax, it will NOT work with CQL 3 (for syntax reasons and because CQL 3.0 drops the very notion of dynamic columns...sigh)
CREATE KEYSPACE test WITH strategy_class = 'SimpleStrategy'
AND strategy_options:replication_factor = '1';
USE test;
CREATE TABLE stats (KEY text PRIMARY KEY) WITH comparator=text AND default_validation=counter;
@klausbrunner
klausbrunner / varnishncsa-request-time-vs-master.patch
Last active October 13, 2015 09:37
Add %D to log complete request time (beginning to end) in varnishncsa. Patches against varnish master & 3.0.3.
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
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 / pullall.py
Last active December 10, 2015 22:29
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
klausbrunner / asset_template.json
Last active December 11, 2015 04:48
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…
{
"asset_template": {
"template": "*",
"settings": {
"analysis": {
"filter": {
"metaphone_filter": {
"replace": false,
"encoder": "doublemetaphone",
"type": "phonetic"
@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 / web.xml
Created December 6, 2013 07:00
web.xml used with cditest, patched weld on jetty-9.1.[01]
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<listener>
<listener-class>org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener</listener-class>
</listener>
<listener>
@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)
@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)