Skip to content

Instantly share code, notes, and snippets.

Klaus Brunner KlausBrunner

View GitHub Profile
@KlausBrunner
KlausBrunner / SimpleFuture.java
Created Nov 19, 2012
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.
View SimpleFuture.java
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 / hls-distances.html
Created Mar 21, 2019
Trivial example to calculate route distances from a fixed point to location(s) specified as user input, using HERE Location Services.
View hls-distances.html
<!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 Dec 10, 2015
Accessing the gerrit SSH interface using Python (via ssh config entry)
View gerrit-ssh.py
#!/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 / two-main-jars-pom.xml
Last active Jan 3, 2019
Creating two different executable JARs with dependencies from the same Maven project - same contents but different Main class in the manifest
View two-main-jars-pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly1</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
@KlausBrunner
KlausBrunner / wars-dist.xml
Created Dec 20, 2012
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.
View wars-dist.xml
<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 Sep 2, 2018
Extracts files and directories of a standard zip file to a destination directory. Requires at least Java 7.
View Unzipper.java
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 / counters.cql
Created Nov 20, 2012
creating and using a Cassandra counter column in CQL
View counters.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 / JacksonStreamingBindingTest.java
Last active Jan 16, 2018
Incrementally binding JSON objects in an array (list) using Jackson.
View JacksonStreamingBindingTest.java
package tv.xrm.test;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
public class JacksonStreamingBindingTest {
@KlausBrunner
KlausBrunner / manifest_growth.py
Last active Oct 3, 2016
Track a repo manifest's project count over time using GitPython. Prints simple "datetime count" table.
View manifest_growth.py
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 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
View 1jetty-weld-howto.md

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: https://github.com/weld/core/pull/465

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

You can’t perform that action at this time.