Skip to content

Instantly share code, notes, and snippets.

View itzg's full-sized avatar

Geoff Bourne itzg

View GitHub Profile
import java.net.URI;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LenientUriConverter {
final static Pattern URL_PATTERN = Pattern.compile("(.+?://.+?)(/+.*?)?([?#].+)?");
// NOTE: /+ normalizes any double slashes in the path
final static Pattern PATHS_PATTERN = Pattern.compile("/+([^/]+)");
import java.time.Duration;
/**
* Tracks if a given activity has happened more times than the requested threshold
* within the requested time window.
*
* <p>
* <b>NOTE</b> this class is <b>not</b> thread-safe. This allows for optimal performance when
* concurrent access is not a factor.
* </p>
@itzg
itzg / SerializeEnumTest.java
Created July 15, 2021 15:15
Trying out JsonProperty to customize enum serialized value
package testing;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class SerializeEnumTest {
@itzg
itzg / promote-anonymous-mc-volume.sh
Last active March 27, 2021 16:28
A procedure to convert anonymous itzg/minecraft-server data volume to a named one
# The following will convert the /data from an existing container named "mc"
# into a named volume "mc" and then create a new, re-configured container
# named "mc-new".
# Keep the old container named "mc" until you have confirmed everything is good
# and then you can cleanup using `docker rm mc`
docker stop mc
docker run --rm --volumes-from mc -v mc:/new alpine cp -avT /data /new
docker run -it --name mc-new -v mc:/data -p 25565:25565 -e EULA=TRUE -e MEMORY=2G itzg/minecraft-server
@itzg
itzg / build.gradle
Created March 21, 2021 22:44
Baseline build.gradle for non-modular JavaFX project
plugins {
// https://docs.gradle.org/current/userguide/application_plugin.html
id 'application'
// https://plugins.gradle.org/plugin/org.openjfx.javafxplugin
id 'org.openjfx.javafxplugin' version '0.0.9'
}
group 'me.itzg'
version '1.0-SNAPSHOT'
@itzg
itzg / Generate lombok-columned POJOs.groovy
Last active February 9, 2021 20:24
For use in IntelliJ's Database Tools and SQL scripts
import com.intellij.database.model.DasTable
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
/*
* Derived from "Generate POJOs.groovy" provided by IntelliJ base install
* Available context bindings:
* SELECTION Iterable<DasObject>
* PROJECT project
* FILES files helper
@itzg
itzg / Chatty.java
Last active January 29, 2021 22:13
What happens when two smallrye incoming methods declared without broadcast
import io.smallrye.mutiny.Multi;
import java.time.Duration;
import java.time.Instant;
import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Outgoing;
@ApplicationScoped
public class Chatty {
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.StringJoiner;
class TryReadTreeAndConvert {
static class Place {
String city;
String state;

docker image inspect IMAGE -f "{{json .Config.Labels}}"

@itzg
itzg / example_using_collectors_toMap.java
Created December 4, 2020 21:23
Using Collectors.toMap with map supplier and mergeFunction
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
class Scratch {
public static void main(String[] args) {
final TreeMap<Object, Object> results = List.of(