Skip to content

Instantly share code, notes, and snippets.

View stefanofago73's full-sized avatar
πŸ’­
Software Designer, I like to build software, a little tormented soul

Stefano Fago stefanofago73

πŸ’­
Software Designer, I like to build software, a little tormented soul
View GitHub Profile
public interface Handler<I, O> {
Result<O> handle(I request, ServiceContext context);
}
public abstract class DelegatingHandler<I, O> implements Handler<I, O> {
@stefanofago73
stefanofago73 / SneakyFns.java
Last active January 24, 2026 17:41
This educational example addresses the issue of checked exceptions in the context of lambdas using an approach that transforms the invocation with a checked exception into a functional interface without exceptions. This is possible thanks to MethodHandles and the LambdaMetafactory. It's also used the approach of the sneaky-throw.
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.function.Function;
/**
*
* This class was triggered form readyn the post: https://blog.frankel.ch/checked-exceptions-lambdas/
* Can be done better and works for unary invocation
*
@stefanofago73
stefanofago73 / CommonCloudEvents_Extensions.java
Last active January 20, 2026 15:24
This is an attempt to pattern the creation of extensions for the CloudEvents Java SDK. There are limitations, but it could be an accelerator for defining existing CloudEvents extensions, including compatibility with the OPC-UA protocol in the context of the IIOT!
import java.net.URI;
import java.time.OffsetDateTime;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import io.cloudevents.CloudEventExtension;
import io.cloudevents.CloudEventExtensions;
import io.cloudevents.core.extensions.impl.ExtensionUtils;
@stefanofago73
stefanofago73 / PlayingWithVarArgs.java
Created December 11, 2025 21:22
This is an example of using var-args, and their definition by the Java compiler as pre-allocated arrays, to simulate in a simple way what is obtained with the Super Type Tokens pattern. Ugly and Raw but... funny enough!
// ----- ELEMENTS TO DEMONSTRATE THE USAGE
public interface Tool {
void use();
}
public record Tool1() implements Tool{
public void use() {
System.out.println("tool1");
}
}
@stefanofago73
stefanofago73 / TryingSWAR.java
Last active December 3, 2025 10:26
A possible, not optimized, SWAR approach without Vector API, searching for ASCII char
public class TryingSWAR{
public final static int[] findCharPositions(String input, byte target) {
final byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
final int trail = bytes.length;
final int[] positions = new int[trail];
final long pattern = 0x0101010101010101L * (target & 0xFF);
int i = 0, idx = 0;
@stefanofago73
stefanofago73 / Problems.java
Created October 11, 2025 08:59
RFC 9457 HTTP Problem Details - Minimal Helper for Spring Boot 2.7.x & C - No dependencies, no libs or frameworks, pure Spring!
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@stefanofago73
stefanofago73 / generic_prompting_guide.txt
Created July 17, 2025 21:14
This guide helps you build effective prompts, reusable context blocks, and structured templates for use in ChatGPT or other LLMs.
# πŸ“˜ Prompting Guide & Reusable Prompt Template (Generic)
This guide helps you build effective prompts, reusable context blocks, and structured templates for use in ChatGPT or other LLMs.
# =========================================
# 🎯 GOALS
# =========================================
- Create concise, reusable prompts
- Maintain low token usage
- Enable restoration of context in future sessions
@stefanofago73
stefanofago73 / Either.java
Last active April 9, 2025 13:40
A simplistic implementation of the Either functional abstraction but using RuntimeException
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
//
// The idea is that the RuntimeException is the Left barnch but implicit!
//
// Exceptions can be Generic, so the "simulation" is partial...
// A better implementation can be using a "type" expressed by
// a Generic Interface that needs to be "instatiated" in the implements moment:
@stefanofago73
stefanofago73 / OptionalCoMonad.java
Created March 29, 2025 16:37
A possible, minimal, Java Optional CoMonad implementation
import java.util.Optional;
import java.util.function.Function;
public final class OptionalCoMonad<T> {
private final Optional<T> value;
private OptionalCoMonad(Optional<T> value) {
this.value = value;
}

THE PROMPT

Act as a PHP Senior Software engineer: You master all modern PHP syntax, data structures, and constructs. temp = 0.4

You are provided with an EBFN grammar, as input, defined inside the tags """.

"""
Grammar ::= ( 
 'SINGLE-WORD' |