Skip to content

Instantly share code, notes, and snippets.

@fResult
fResult / PricingDiscountApp.java
Last active June 3, 2025 10:36
Example for the article https://fresult.medium.com/31014f433b49 and POC Strategy Design Pattern
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
class PricingDiscountApp {
public static void main(String[] args) {
final var customer1 = new Customer("1", "John Doe", CustomerType.VIP);
final var customer2 = new Customer("2", "Jane Doe", CustomerType.REGULAR);
final var customer3 = new Customer("3", "Business Corp", CustomerType.BUSINESS);
import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
class DocumentProcessorApp {
public static void main(String[] args) {
final var trinity = new Submitter("trin123");
final var morpheus = new Approver("morph456");
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
class TripAnalyzerApp1 {
private static final List<Trip> TRIPS = List.of(
new Trip(TripType.BUSINESS, "Tokyo", Duration.ofHours(5),LocalDateTime.of(2025, 5, 25, 8, 0), "Thomas Anderson", new BigDecimal("1200.00")),
import static java.time.temporal.ChronoUnit.HOURS;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Supplier;
@fResult
fResult / TestSecureResource1.java
Last active May 11, 2025 16:25
Try Union Type In Java
sealed interface Permission permits Read, Write {}
record Read() implements Permission {}
record Write() implements Permission {}
record Execute() {}
class ResourceAction {
public String perform(Permission permission) {
return String.format("Performing action with %s...", permission.getClass().getSimpleName());
}
@fResult
fResult / Customer.java
Last active April 20, 2025 13:29
Optional Demo for the article: https://medium.com/p/03845513d9f5 (You can see the whole code block at the file in the bottommost.)
// Basic domain record
public record Customer(String id, String email) {}
@fResult
fResult / LAB_FAILED.md
Last active March 11, 2025 14:15
Implement Load Balancing on Compute Engine Failed

GCP Skills Boost - Challenge Lab

Test Passed:

image

But check progress failed:

image

@fResult
fResult / MostAppearedDigitsProblem.java
Last active February 21, 2025 04:54
Solve the mostAppearedDigits without using `maximum` utility method
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
class TestUtils {
public static <Expected, Actual> void test(Expected expectedResult, Actual actualResult) {
// System.out.printf("Expected=%s | Actual=%s\n", expectedResult, actualResult);
final var expectedResultOpt = Optional.ofNullable(expectedResult);
final var actualResultOpt = Optional.ofNullable(actualResult);
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
class TestUtils {
public static <Expected, Actual> void test(Expected expectedResult, Actual actualResult) {
// System.out.printf("Expected=%s | Actual=%s\n", expectedResult, actualResult);
final var expectedResultOpt = Optional.ofNullable(expectedResult);
final var actualResultOpt = Optional.ofNullable(actualResult);