Skip to content

Instantly share code, notes, and snippets.

View klausbrunner's full-sized avatar

Klaus Brunner klausbrunner

View GitHub Profile
@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 / JacksonStreamingBindingTest.java
Last active March 14, 2021 05:14
Incrementally binding JSON objects in an array (list) using Jackson.
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 / two-main-jars-pom.xml
Last active February 2, 2020 15:17
Creating two different executable JARs with dependencies from the same Maven project - same contents but different Main class in the manifest
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly1</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
@klausbrunner
klausbrunner / curltest.sh
Created October 7, 2014 08:21
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
klausbrunner / findhash.py
Created June 1, 2015 15:18
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 github3.py 0.9.4.
"""
@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 / 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 / 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 / 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 / sshd_config
Last active April 13, 2020 13:42
Minimal, secure sshd_config (OpenSSH 8.2)
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
ChallengeResponseAuthentication no
UsePAM yes
# Allow client to pass locale environment variables