Skip to content

Instantly share code, notes, and snippets.

View thomasdarimont's full-sized avatar
🏠
Working from home

Thomas Darimont thomasdarimont

🏠
Working from home
View GitHub Profile
@thomasdarimont
thomasdarimont / LocalOnceExample.java
Created September 22, 2021 20:58
Example usage for statics in local classes for one-time computation with Java 17
public class LocalOnceExample {
public static void main(String[] args) {
foo();
foo();
}
static int foo() {
System.out.println("start foo");
class Local {
@thomasdarimont
thomasdarimont / StaticsInLocalClassesExample.java
Created September 22, 2021 15:29
Example for using static in a local class for memoization
package wb.java17;
import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class StaticsInLocalClassesExample {
public static void main(String[] args) {
System.out.println(factorial(120));
@thomasdarimont
thomasdarimont / index.js
Created August 18, 2021 21:37
Inline WebWorker example
let code = `self.onmessage = msg => { console.log("Worker: %s", msg.data.text)}`;
const worker = new Worker("data:,"+code);
worker.postMessage({text: 'Hello from main thread!'});
@thomasdarimont
thomasdarimont / main.go
Last active May 11, 2022 20:44
Simple golang webserver with custom Socket Option SO_REUSEPORT to run multiple processes on the same port
package main
import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"syscall"
@thomasdarimont
thomasdarimont / index.html
Last active April 8, 2024 14:10
Mini SPA with Keycloak.js with support for PKCE and RAR
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Keycloak SPA Demo</title>
<style>
body {

docker run -it --rm --user 0 -v $PWD/caddy/caddy.json:/etc/caddy.json:z --entrypoint /bin/sh caddy:2.4.2-alpine

@thomasdarimont
thomasdarimont / haproxy-servers.cfg
Created June 16, 2021 22:37 — forked from rduplain/haproxy-servers.cfg
Rewrite haproxy configuration and reload service.
# Edit this file then run `update-haproxy haproxy-servers.cfg`.
# Alternatively, use a shell pipeline to build server list `... | update-haproxy`.
server demo1 127.0.0.1:8001 check cookie demo1 weight 100
server demo2 127.0.0.1:8002 check cookie demo2 weight 100
server demo3 127.0.0.1:8003 check cookie demo3 weight 0
server demo4 127.0.0.1:8004 check cookie demo3 weight 0
@thomasdarimont
thomasdarimont / readme.md
Last active March 23, 2022 19:04
Run an Embedded Keycloak Server with JBang

The example uses the embedded Spring Boot Keycloak Server to quickly spin up a new Keycloak instance.

Create JBang script with

jbang init spring-keycloak-server

Adapt spring-keycloak-server script.

Run the Keycloak server via:

@thomasdarimont
thomasdarimont / README-fail2ban-keycloak.md
Created May 18, 2021 08:03 — forked from drmalex07/README-fail2ban-keycloak.md
Use fail2ban to block brute-force attacks to keycloak server. #keycloak #fail2ban #brute-force-attack

Add regular-expression filter under /etc/fail2ban/filter.d/keycloak.conf:

[INCLUDES]

before = common.conf

[Definition]

_threadName = [a-z][-_0-9a-z]*(\s[a-z][-_0-9a-z]*)*
_userId = (null|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})
@thomasdarimont
thomasdarimont / OnceDemo.java
Created April 29, 2021 17:58
Java experiment for an golang like "sync.Once" primitive
package demo.once;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;