Skip to content

Instantly share code, notes, and snippets.

View xpepper's full-sized avatar
💭
😏

Pietro Di Bello xpepper

💭
😏
View GitHub Profile
@xpepper
xpepper / kill_rancher_desktop_leftovers.sh
Created January 27, 2025 21:40
Kill all Rancher Desktop leftover to be able to use again Warp client :D
#!/bin/bash
# Find all processes matching 'socket_vmnet' and kill them
ps auxwww | grep -i socket_vmnet | grep -v grep | awk '{print $2}' | xargs sudo kill

Talking about chapter 6, I want to add a question on the part where the author states "of course, we could add special runtime validation checks to make sure that this couldn’t happen."

image

The question is: Aren’t the check pushed to the edge of the system? Somewhere there will be logic for deciding if we want to create a EmailContactInfo, PostalContactInfo or BothContactMethods. Shouldn’t this logic be (unit) tested?

For sure the logic for deciding whether to create an EmailContactInfo, PostalContactInfo, or BothContactMethods does need to be implemented somewhere! In fact, this decision-making logic—let's call it the "creation logic"—becomes the entry point where the business rule is enforced. Here's how that ties into the points raised in the book and your question:

1. Pushing Validation to the Edges

Scott Wlaschin advocates for embedding business rules directly in th

@xpepper
xpepper / dmmf_chapter6_create_types_aggressively.md
Created January 26, 2025 15:17
Are we used to create too few types to model our domains?

One thing I’m getting by reading chapter 6 is that we typically create very few types for describing and modeling a business domain, while one of the key learnings I got from this chapter that we should aggressively create types to capture differences and nuances, and to properly describe the different states of business workflows. (e.g. not an EmailAddress but a UnverifiedEmailAddress and a VerifiedEmailAddress)

Chapter 6 is all about using types as a way to explicitly model and describe the domain in a precise and meaningful way. This means creating types to capture subtle differences and distinctions in your domain that are often overlooked when using a less type-focused approach.

So, yes, we should aggressively create types when modeling a business domain. This isn’t about creating types for the sake of complexity but rather about creating types to represent the real-world states and constraints of your business workflows in a clear, unambiguous way. This helps make your code more expres

@xpepper
xpepper / dmmf_chapter6_exercises.md
Last active January 27, 2025 22:35
Domain Modeling Made Functional - What are other practical thought exercises I could do at the end of chapter 6?

Here are some practical exercises we could do:


1. Identify Invariants in Your Own Domain

Think about a real-world system you're familiar with (e.g., a shopping cart, a library management system, a flight booking system). For each one:

  • List out the core entities in the domain.
  • Identify the key business rules (invariants) that must always hold true.
  • Ask yourself: How would you model these rules as types and functions?
@xpepper
xpepper / dmmf_chapter5-order-orderline.md
Last active January 26, 2025 15:14
Domain Modeling Made Functional - chapter 5 - order and order line

In chapter 5, p.95, Scott writes:

"First, is Order an Entity or a Value Object? Obviously it’s an Entity—the details of the order may change over time, but it’s the same order.

What about an OrderLine, though? If we change the quantity of a particular order line, for example, is it still the same order line? In most designs, it would make sense to say yes, it is still the same order line, even though the quantity or price has changed over time. So OrderLine is an Entity too, with its own identifier.

But now here’s a question: if you change an order line, have you also changed the order that it belongs to?

In this case, it’s clear that the answer is yes: changing a line also changes the entire order. In fact, having immutable data structures makes this unavoidable. If I have an immutable Order containing immutable OrderLines, then just making a copy of one of the order lines does not also make a copy of the Order as well. In order to make a change to an OrderLine contained in an Order, I need to make the c

@xpepper
xpepper / dmmf_chapter5_unique.ids.md
Last active January 26, 2025 15:14
Given that entities need to have a stable identity over time, they require a unique identifier or key. Who is responsible for creating these identifiers? Where do these identifiers come from?

So, given that entities need to have a stable identity over time, they require a unique identifier or key. Who is responsible for creating these identifiers? Where do these identifiers come from?

The responsibility for creating unique identifiers (keys) for entities in a domain-driven design (DDD) system depends on the context and requirements of the application. There are several common approaches to generating these identifiers, each suited to specific use cases. Let’s explore these approaches and who is responsible for generating the identifiers in each case.

The Domain

In some domains, the identifier is inherent to the entity itself and comes from the real-world domain.

Examples:

  • Serial numbers for banknotes: In the state mint context, the identifier (serial number) is usually assigned during the manufacturing process. The mint’s production system generates the serial number and ensures uniqueness.
@xpepper
xpepper / custom.router.md
Last active February 24, 2025 22:08
To setup a custom DNS on your TIM ZTE H388X router

To setup a custom DNS on your TIM ZTE H388X router:

  • head to "Rete Locale" -> "LAN" -> Server DHCP
  • execute this script in the browser dev tools console
document.querySelectorAll('#template_DHCPBasicCfg [style*="display: none;"]').forEach(el => {
    el.style.display = ''; // Removes inline display:none
});
  • you should see
@xpepper
xpepper / rancher.sh
Last active October 24, 2024 14:56
Start / stop Rancher Desktop (on macOS)
#!/bin/bash
# Default action is 'start'
ACTION="${1:-start}"
POST_START_COMMAND="$2"
if [ "$ACTION" == "start" ]; then
# Check if Rancher Desktop is already running
if docker ps &> /dev/null; then
echo "Rancher Desktop is already running."
@xpepper
xpepper / generate-commit.sh
Last active April 30, 2024 19:44
An AI-driven git commit message generator. It needs a valid OpenAI key set as an env variable`OPENAI_API_KEY`. It works on macOS, needs curl and jq in order to work.
#!/bin/bash
OPENAI_API_KEY="${OPENAI_API_KEY}"
HOST="https://api.openai.com"
MODEL="gpt-3.5-turbo"
# Check if the API key is set
if [ -z "$OPENAI_API_KEY" ]; then
echo "OpenAI API key is not set. Please set the OPENAI_API_KEY environment variable."
exit 1

If you want to invest your next learning session with a code kata (TL;DR: you should), here's an opinionated list of kata catalogs:

Remember, when tackling a kata, you should first have a clear idea of what you want to learn or what skills you want to sharpen (e.g., improving TDD skills, refactoring skills, code design skills, etc.). If you want to impr