Skip to content

Instantly share code, notes, and snippets.

View klausbrunner's full-sized avatar

Klaus Brunner klausbrunner

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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
@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 / 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 {