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
@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' | 
@stefanofago73
stefanofago73 / chatgpt_against_DDD.md
Created November 28, 2023 12:57
This is a joke to create a post criticizing DDD but using ChatGPT

Navigating the Quirky Waters of Domain Driven Design: A Humorous Expedition

THE PROMPT

Act as an expert of Domain Driven Design, temp 0.4

Task:

  • Your task is to write a full-fledged blog post about all defects of Domain Driven Design using jokes and important quotes from Alberto Brandolini's posts, books and works.

Format:

@stefanofago73
stefanofago73 / DSL_Generated.java
Last active October 23, 2023 13:04
An example of ChatGPT prompt to generate the source code for a simple Domain Specific Language
/**
*
* Here we have the originating grammar
*
* Grammar ::= (
* 'SINGLE-WORD' |
* 'PARAMETERISED-WORD' '('[A-Z]+')' |
* 'WORD1' 'OPTIONAL-WORD'? |
* 'WORD2' ( 'WORD-CHOICE-A' | 'WORD-CHOICE-B' ) |
* 'WORD3'+
@stefanofago73
stefanofago73 / TypeClasses_Exampls.java
Created October 8, 2023 20:25
Are possible Haskell Typeclasses in Java?
//
// Empty Typeclass
//
interface Empty<A> {
A empty();
static Empty<Integer> emptyInt() {
return () -> 0;
}