Skip to content

Instantly share code, notes, and snippets.

View nipafx's full-sized avatar

Nicolai Parlog nipafx

View GitHub Profile
class PostCountTests {
@Until2025Test
void jepcafes(@FromTemplate(VideoSeriesEpisodePage.class) @ForSlug("/jepcafe/.*") List<RenderedPage> pages) {
assertThat(pages).hasSize(24);
assertThat(extractEpisodeNumbers(pages, "/jepcafe/")).isEqualTo(firstNIntegers(24));
}
@Until2025Test
void newscasts(@FromTemplate(VideoSeriesEpisodePage.class) @ForSlug("/newscast/.*") List<RenderedPage> pages) {
@nipafx
nipafx / WikiStream.java
Created September 16, 2025 18:47
Stream and process Wikipedia change events (note TODOs at top of file)
// TODO for setup:
// * needs com.fasterxml.jackson.core:jackson-databind and dependencies on the class path
// * needs a valid email address in `EMAIL`
import module java.net.http;
import com.fasterxml.jackson.databind.*;
static final ObjectMapper MAPPER = new ObjectMapper();
static final String DATA_LINE_PREFIX = "data: ";
static final URI WIKI_URL = URI.create("https://stream.wikimedia.org/v2/stream/mediawiki.recentchange");
@nipafx
nipafx / DOCUMENTATION.md
Last active July 25, 2025 21:27
A wrapper for SDKMAN that makes it easier to install the latest JDK version and update a symlink to it that allows setting a java version with, e.g., `sdk use java 25`

Setup:

  1. have SDKMAN installed
  2. copy the content of JdkUpdate.java into a file jdk_update
  3. make it executable with chmod +x jdk_update
  4. either add it to the path or execute from within that directory

Features / how-to:

  • a command like jdk_update 24.0.2-open:
@nipafx
nipafx / FizBuzz.java
Created July 27, 2024 11:16
Some FizzBuzz
// based on https://github.com/Ocean-Moist/FizzBuzz/blob/master/src/Main.java
// from https://rohan.ga/blog/java/
// run on JDK 23 with `java --enable-preview FizzBuzz.java`
void main() {
var testers = List.of(
new Tester(x -> x % 3 == 0, "Fizz"),
new Tester(x -> x % 5 == 0, "Buzz"));
IntStream
.rangeClosed(1, 100)
@nipafx
nipafx / .gitconfig
Created August 8, 2023 15:04
My Git aliases
[alias]
st = status --branch --short
look = log --graph --pretty='%C(red)%h%Creset %C(green)%ad%Creset %C(yellow)%<(15,trunc)%an%Creset %s %C(bold blue)%D%Creset' --date=format-local:'%d.%m.%Y %H%M'
look-close = log --graph --pretty='%C(red)%h%Creset %C(green)%cd%Creset %C(yellow)%<(15)%cn%Creset %C(bold blue)%D%Creset%n %C(dim green)%ad%Creset %C(dim yellow)%<(15)%an%Creset %s' --date=format-local:'%d.%m. %H%M'
hist = log --pretty='%C(red)%h%Creset %C(green)%cd%Creset %C(yellow)%<(12,trunc)%an%Creset %s %C(auto)%D%Creset' --date=format-local:'%Y-%m-%d %H:%M'
wat = !git look -15
cd = checkout
patch = -c interactive.diffFilter='diff-highlight | less -FRX --tabs=4' add --patch
unstage = reset HEAD --
unstage-patch = reset HEAD --patch
@nipafx
nipafx / Store.java
Last active May 18, 2022 10:00
Non-asyncronous EA Async example
// Two examples [1, 2] from EA Async written without async/await or
// (Completable)Futures as straight-forward blocking code. If the
// callers want to do something concurrently to `Store::buyItem`,
// they just put that call into a new virtual threads.
public class Store {
private final Bank bank = new Bank();
private final Inventory inventory = new Inventory();
@nipafx
nipafx / Tree.java
Last active July 9, 2021 11:04
Counting Red Nodes in a Colored Tree
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;
// implementation of https://twitter.com/peterzllr/status/1413216826708877318
public class Tree {
public static void main(String[] args) {
var tree = new Red(
new Black(
@nipafx
nipafx / multilines.md
Last active February 21, 2024 16:58
Creating multiline strings in JS, Groovy, Kotlin, and Java

#1 Split "one", "two" across two lines

Goal:

one\n
two

Onboard JavaScript requires us to break the code formatting.

@nipafx
nipafx / Lab.java
Created May 27, 2020 07:49
Optional vs null && Stream vs loop
package org.codefx.lab;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
class Lab {
@nipafx
nipafx / example.xml
Created April 30, 2020 08:53
Configuring Maven's copy-dependencies MOJO
<!-- executed during build -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version><!-- currently 3.1.2 --></version>
<executions>
<execution>
<!-- with this ID, the command above picks up the config -->
<id>default-cli</id>
<!-- if `process-sources` doesn't match your needs -->
<phase>package</phase>