Skip to content

Instantly share code, notes, and snippets.

View sleberknight's full-sized avatar

Scott Leberknight sleberknight

  • Fortitude Technologies
  • Leesburg, VA
View GitHub Profile
@sleberknight
sleberknight / round-robin-multi-executor-1.txt
Last active January 15, 2025 19:07
Sample output from running the consul-client testing apps for round robin failover strategy
Starting reader 1
[reader 1 [pool-2-thread-1]]: Attempt #1 to call getValueAsString
Starting reader 2
[reader 2 [pool-2-thread-2]]: Attempt #1 to call getValueAsString
22:05:28.219 [pool-2-thread-1] WARN o.k.c.u.f.ConsulFailoverInterceptor - Got 'java.net.UnknownHostException:a.foo.bar.baz: Name or service not known' when connecting to http://a.foo.bar.baz:8500/v1/kv/foo (enable DEBUG level to see stack trace)
22:05:28.219 [pool-2-thread-2] WARN o.k.c.u.f.ConsulFailoverInterceptor - Got 'java.net.UnknownHostException:a.foo.bar.baz' when connecting to http://a.foo.bar.baz:8500/v1/kv/foo (enable DEBUG level to see stack trace)
Starting reader 3
[reader 3 [pool-2-thread-3]]: Attempt #1 to call getValueAsString
22:05:28.271 [pool-2-thread-3] WARN o.k.c.u.f.ConsulFailoverInterceptor - Got 'java.net.UnknownHostException:a.foo.bar.baz' when connecting to http://a.foo.bar.baz:8500/v1/kv/foo (enable DEBUG level to see stack trace)
22:05:28.298 [pool-2-thread-1] WARN o.k.c.u.f.ConsulFailoverInterceptor - Got 'java.
@sleberknight
sleberknight / JdbiTestUtils.java
Last active November 1, 2024 15:02
Some simple JDBI test utilities
package com.acme.test.jdbi;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.jdbi.v3.core.Handle;
import java.util.Arrays;
// As these are TEST utilities, they do not bother about SQL injection, etc.
// Clearly, you should NEVER use these in production code!
@sleberknight
sleberknight / App.java
Last active October 17, 2024 15:30
Changes to dropwizard-service-utils to make it a Dropwizard App for testing FreePortFinder implementations
package org.kiwiproject.dropwizard.util;
import lombok.extern.slf4j.Slf4j;
import org.kiwiproject.dropwizard.util.bundle.DynamicPortsBundle;
import org.kiwiproject.dropwizard.util.bundle.DynamicPortsConfiguration;
import org.kiwiproject.dropwizard.util.server.DropwizardConnectors;
import java.util.Map;
import java.time.Instant;
@sleberknight
sleberknight / JacksonPolymorphicDeserializationExample.java
Last active October 16, 2024 20:40
Jackson Polymorphic Deserialization Example
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.ObjectMapper;
// This uses JsonSubTypes to declare the subtypes, which is not flexible.
// Alternatively, you can create a SimpleModule and register subtypes
// using registerSubtypes. The add the module to your ObjectMapper.
// Base class
@sleberknight
sleberknight / LeadershipStatus.java
Created August 23, 2024 21:03
LeadershipStatus sealed interface and record implementations
package org.kiwiproject.curator.leader;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.framework.recipes.leader.LeaderLatch;
/**
* A proposed definition for a type that can be returned when checking
* if a LeaderLatch (from Apache Curator) has leadership, taking into
* account the various issues that can cause problems.
* <p>
query {
repository(owner: "kiwiproject", name: "kiwi") {
milestone(number: 44) {
title
issues(first: 100) {
nodes {
number
title
url
state
@sleberknight
sleberknight / show-git-logs.md
Last active July 17, 2024 13:59
Some git log commands

Basic git log with 'decorate' option

git log --decorate

This shows references (including tags) in the commit log.

One-line git log with decoration

@sleberknight
sleberknight / ConfigurationHelpers.java
Last active June 14, 2024 13:56
Configuration helper / generic object methods to select a value or a fallback
// See the ConfigurationHelpers in java-scratch-pad (private repo)
@UtilityClass
public class ConfigurationHelpers {
public static <T> Optional<T> selectOrEmpty(T preferred, T fallback) {
var result = selectOrNull(preferred, fallback);
return Optional.ofNullable(result);
}
@sleberknight
sleberknight / ThrowOrNullCallable.java
Created June 5, 2024 14:17
Callable that throws exception or returns null until limit reached
package org.kiwiproject.example;
import static java.util.Objects.nonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
/**
@sleberknight
sleberknight / custom-init.jsh
Created May 29, 2024 16:44
Custom jshell init script
import java.math.*;
import java.nio.*;
import java.nio.charset.*;
import java.nio.file.*;
import java.time.*;
import java.time.chrono.*;
import java.time.format.*;
import java.time.temporal.*;