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
<?php declare(strict_types = 1);
// ====================================================================
//
// Copy and Paste on https://3v4l.org/
// PHPStan & Psalm verified...
// Some code isn't the best but I want to transmit the ideas!
//
// ====================================================================
@stefanofago73
stefanofago73 / RandomEnumGenerator.php
Created May 16, 2022 20:15
Example of Usage of UnitEnum, Template and Callable to obtain a "generic function"...
<?php declare(strict_types = 1);
/**
* @template T of \UnitEnum
* @param class-string<T> $enumType
* @return callable():T
**/
function randomEnumGenerator(string $enumType):callable
{
/** @var array<T> $cases **/ $cases = [$enumType,"cases"]();
import java.util.HashMap;
import java.util.function.Function;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.Random;
interface Visitable<R,T extends Visitable<R,?>> {
@stefanofago73
stefanofago73 / MDC.md
Created August 30, 2022 07:33
A simple skeleton to render Microservice Design Canvas in Plantuml/Ditaa... You can also experimenting online for free with [ https://www.planttext.com/ ]

@startditaa

+-------------------+-------------------------------------------+
| Service Name | Description | | | | | | | | | | +-------------------+-------------------------------------------+ | Consumer Task / Capabilities | | |

@stefanofago73
stefanofago73 / ForComp_ScalaPorting.java
Last active January 15, 2023 08:27
Porting Scala For-Comprehension usage examples in pure Java 8+ examples ( at least some interesting examples )
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
/**
*
* @author Stefano fago
@stefanofago73
stefanofago73 / IceCreamFactory.java
Last active January 17, 2023 14:29
A study on extracting a list of values from a list of Optionals: What implementation? And why?
import static java.util.stream.Collectors.toList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
/**
*
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
interface ListDefinition<R> extends Supplier<List<R>>{
default boolean canMutate() {
return false;
}
@stefanofago73
stefanofago73 / CharSequences.txt
Last active February 10, 2023 10:04
Reasoning about CharSequence: my weird dreams.
Starting point:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/CharSequence.html
Points:
- This interface provides uniform, read-only access to many different kinds of char sequences.
- This interface does not refine the general contracts of the equals and hashCode methods. The result of testing two objects that implement CharSequence for equality is therefore, in general, undefined.
- toString method: Returns a string containing the characters in this sequence in the same order as this sequence.
So... Those point, in someway, dont' make me happy also if I consider what are the implementation... CharBuffer, StringBuilder, String...
@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;
}
@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'+