Skip to content

Instantly share code, notes, and snippets.

View itzg's full-sized avatar

Geoff Bourne itzg

View GitHub Profile
@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(
@itzg
itzg / gist:9672f9f1ea322587b3faa9de53c63e49
Created October 23, 2020 21:03
JVM processor count when running on Kubernetes derivs from resources.limits.cpu
resources:
requests:
cpu: 4000m
memory: 4Gi
limits:
cpu: 5000m
memory: 4Gi
: ${JMX_HOST:=0.0.0.0}
: ${JMX_PORT:=7091}
JVM_OPTS="${JVM_OPTS}
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.port=${JMX_PORT}
-Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT}
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.host=${JMX_HOST}
-Djava.rmi.server.hostname=${JMX_HOST}"
@itzg
itzg / gist:890f16edf919a8bde777fbef02e3733f
Created October 11, 2020 16:31
With Spring's WebClient, how to ensure kubernetes service load balancing actually gets used
# unit is milliseconds
-Dreactor.netty.pool.maxLifeTime=10000
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class ConsumerService {
@KafkaListener(topics = "my-topic")
public void consumeMessage(String message) {
@itzg
itzg / gist:31080bb98838508a6374b9daf52ad72a
Created August 27, 2020 19:16
Convert markdown file to Word DOCX using pandoc docker image
docker run --rm -v ${PWD}:/data pandoc/latex input.md -o output.docx
@itzg
itzg / _install.md
Created July 18, 2020 14:50
oh-my-zsh custom plugin that helps me develop from within WSL2

Create the directory $ZSH_CUSTOM/wsl-helpers and place the wsl-helpers.plugins.zsh file in that directory.

@itzg
itzg / docker-compose.yml
Last active June 11, 2020 18:09
v1 style example of docker compose for rcon-web-admin
web:
image: itzg/rcon
environment:
RWA_USERNAME: admin
RWA_PASSWORD: admin
RAW_ADMIN: "TRUE"
# is referring to the hostname of 'mc' compose service below
RWA_RCON_HOST: mc
# needs to match the password configured for the container, which is 'minecraft' by default
RWA_RCON_PASSWORD: minecraft
import java.util.Arrays;
import java.util.List;
class ExampleOfComposableExpressions {
public static void main(String[] args) {
// Equivalent to
// expr := ( (idle <= 10) || (usage > 80) ) && (available =~ /^y(es)?/)
Expression expr =
new LogicalExpression(
@itzg
itzg / KafkaStreamsMetricsConfig.java
Last active March 28, 2022 17:07
Spring Boot does not auto-bind Kafka Streams metrics in its KafkaMetricsAutoConfiguration, so this does the metrics binding similarily for Kafka Streams
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.kafka.KafkaStreamsMetrics;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.StreamsBuilderFactoryBeanCustomizer;
/**
* Binds a micrometer {@link KafkaStreamsMetrics} to the meter registry
* for each Kafka stream created by Spring.
*/