Skip to content

Instantly share code, notes, and snippets.

View jkschneider's full-sized avatar

Jonathan Schnéider jkschneider

View GitHub Profile

How many places does my birthday exist in our source code?

Let's get a bit more specific. How many places does the year of my birthdate exist in a literal somewhere in the codebase. Comments don't count. Variable names don't count.

Can you imagine doing something like this with a regular expression?

// 12-05-1983
class Hey {
  void itsYourBirthday() {
⚠️
📈
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.konghq:unirest-java:3.14.2
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.io.*;
import java.util.concurrent.*;
import java.util.function.Consumer;
ExecutorService executorService = Executors.newSingleThreadExecutor();
System.out.println("Executing command: " + args[0]);
try {
Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", args[0]});
StringBuilder sb = new StringBuilder();
Result "org.openrewrite.benchmarks.java.StarImportBenchmark.noStarImport":
N = 238
mean = 333.142 ±(99.9%) 10.826 ms/op
Histogram, ms/op:
[200.000, 225.000) = 0
[225.000, 250.000) = 0
[250.000, 275.000) = 19
[275.000, 300.000) = 59
[300.000, 325.000) = 56
package io.moderne.common.monitoring;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.openrewrite.internal.lang.NonNull;
import oshi.SystemInfo;
import oshi.hardware.GlobalMemory;
@jkschneider
jkschneider / DataBuffersInputStream.java
Last active June 4, 2022 22:50
Turns a `Flux<DataBuffer>` into an `InputStream`
class DataBuffersInputStream extends InputStream {
volatile DataBuffer currentBuf;
volatile boolean complete;
BaseSubscriber<DataBuffer> subscriber = new BaseSubscriber<>() {
@Override
protected void hookOnNext(DataBuffer buf) {
releaseCurrentBuf();
currentBuf = buf;
((NettyDataBuffer) buf).retain();
package org.openrewrite.gradle;
import org.openrewrite.Option;
import org.openrewrite.Recipe;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.semver.DependencyMatcher;
public class ChangeDependencyVersionFromEnv extends Recipe {
@Option(displayName = "Dependency pattern",
description = "A dependency pattern specifying which dependencies should have their groupId updated. " +
package org.openrewrite.java.spring;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.*;
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;
public class WebClientMaxConnections extends Recipe {
package org.openrewrite.java.dataflow;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import java.util.function.Predicate;
import static org.apache.commons.lang.StringUtils.startsWith;