Skip to content

Instantly share code, notes, and snippets.

View rponte's full-sized avatar
🏠
Working from home

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile
@rponte
rponte / CreateChargeForCustomer.py
Last active January 7, 2025 12:45
Example of code in Python to create a charge for a specific customer
async def create_charge(charge: Charge, customer: Customer) -> None:
if not customer.is_active():
raise Customer InactiveError("The customer is not active.")
if not charge.has_valid_amount():
raise InvalidChargeAmountError("The charge amount must be greater than zero.")
if not charge.has_valid_due_date():
raise InvalidDueDateError("The due date must be in the future.")
@rponte
rponte / 01-BookRequestTest.java
Last active February 22, 2025 02:19
Spring Boot Testing: How to test the Bean Validation annotations in domain and DTO objects without starting the whole Spring Boot Context
import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
@rponte
rponte / spinlocks.md
Created December 12, 2024 13:51 — forked from tef/spinlocks.md

fair, fine grained, and deadlock free locking

first, a spin lock

you know what a spinlock is, right?

here's a spinlock:

@rponte
rponte / command-llm-server-ports.sh
Last active December 11, 2024 15:17
Shell Script: One-line command combined with LLM (AI) to evaluate servers that are running locally and their criticality
# Brilliant one-liner
(echo "PID COMMAND PORT USER"; lsof -i -P -n | grep LISTEN | awk '{print $2, $1, $9, $3}' | sort -u | head -n 50; echo;) \
| column -t \
| llm "what servers are running on my machine and do some of them look like they could be orphaned things I can shut down"
# Maybe even more brilliant one liner
(echo "PID COMMAND PORT USER"; lsof -i -P -n | grep LISTEN | awk '{print $2, $1, $9, $3}' | sort -u | head -n 50) \
@rponte
rponte / TempClasspathDirCreator.java
Created November 19, 2024 17:41
Helper class to create temp files inside application classpath during the unit tests with Java and jUnit
package base;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@rponte
rponte / 01-SshService.java
Last active December 11, 2024 14:44
Example of Integration Tests with Java, jUnit5 and Apache Mina to execute remote commands via SSH
package br.com.rponte.sample.ssh;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
@rponte
rponte / postgresql_serializable_isolation.sql
Created October 25, 2024 15:05 — forked from nathanl/postgresql_serializable_isolation.sql
PostgreSQL Serializable Isolation - false positives
-- (This code was run in PostgreSQL 9.6.1)
-- Demonstration of how serializable isolation for PostgreSQL, which detects possible
-- interference between concurrent transactions, can produce false positives
-- in psql, create the following table
CREATE TABLE users(
id SERIAL NOT NULL PRIMARY KEY,
username VARCHAR NOT NULL
);
@rponte
rponte / partitioning.md
Last active February 4, 2025 13:36
Patitioning: the third pillar of scalability
@rponte
rponte / races-conditions.md
Created September 2, 2024 15:16 — forked from rafaelpontezup/races-conditions.md
Chapter Stackspot: Race conditions, locking e bancos de dados relacionais

Race conditions, locking e bancos de dados relacionais

Pretendo apresentar um código com uma lógica de negócio simples que funciona bem na perspectiva do negócio mas que quebra miseravelmente em ambientes minimamente concorrentes. Para isso, vou demonstrar através de testes de integração como identificar o Race Condition no código e principalmente como resolvê-lo através de mecanismos de locking e Isolation Level do seu banco de dados;

O que vamos discutir

  1. Por que estudamos esse assunto mais a fundo?
  • 1.3. A importância do treino: o que eu levei alguns bons anos para aprender o Jordi levou 6 meses
@rponte
rponte / README.md
Last active January 5, 2024 19:19
StackSpot Action: action responsible for creating a Gitlab repository written in Python

Create Repository Gitlab

Creates a new repository (aka project) in a specific Gitlab group.

How to set up this project

This project was developed with Python v3.9, and it also uses Python's Virtualenv tool. So before working on this project we need to set up it.

Inside this project's folder, execute those commands to configure your environment: