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 / CreateNewUserController.java
Last active March 26, 2025 18:27
Designing fault-tolerant and idempotent APIs with HTTP requests mapped to database's transactions at 1:1 model
/**
* This Spring Boot controller was implemented as an example of a simple but robust idempotent REST API that
* leverages the ACID properties of a relational database.
*/
@RestController
public class CreateNewUserController {
@Autowired
private UserRepository repository;
@Autowired
@rponte
rponte / AccountRepository.java
Last active December 18, 2024 19:55
JPA and Hibernate: Simple and Smart way of using PostgreSQL Advisory Locks with JPQL to prevent Lost Update anomaly
package br.com.rponte.nullbank.withdrawal;
import org.hibernate.LockOptions;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import javax.persistence.LockModeType;
import javax.persistence.QueryHint;
import javax.transaction.Transactional;
import java.util.Optional;
@rponte
rponte / BookRepositoryTest.java
Last active January 17, 2024 19:57
Spring Boot: example of base test class for testing Repositories
package br.com.zup.edu.ifoodwebapp.samples.books;
import base.SpringDataJpaIntegrationTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.TransactionSystemException;
@rponte
rponte / Book.java
Last active December 17, 2024 14:09
AssertJ: Example of a jUnit5 test for asserting Bean Validation errors thrown by Spring Boot Repository
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.ISBN;
import java.util.Objects;
import static org.hibernate.validator.constraints.ISBN.Type.ISBN_13;
@rponte
rponte / how-to-fix.md
Last active December 2, 2024 22:15
Git clone and SSL certificate problem: "unable to get local issuer certificate" and "server certificate verification failed. CAfile: none CRLfile: none"

The issue with SSL certificate

Just out of the blue, I started getting this issue ("server certificate verification failed. CAfile: none CRLfile: none") while trying to clone any Github repository on Linux (WSL2):

git clone https://github.com/rafaelpontezup/preventing-lost-update-racecondition.git
Cloning into 'preventing-lost-update-racecondition'...
fatal: unable to access 'https://github.com/rafaelpontezup/preventing-lost-update-racecondition.git/': server certificate verification failed. CAfile: none CRLfile: none

And also with Window 11 I got "SSL certificate problem: unable to get local issuer certificate":

@rponte
rponte / simple_schema.sql
Created February 13, 2023 17:06
SQL and Postgres: simple schema that can be used as example
DROP TABLE customers, invoices, items;
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE invoices (
invoice_id SERIAL PRIMARY KEY,
customer_id BIGINT REFERENCES customers (customer_id)
@rponte
rponte / speed-at-scale-breaks-everything.md
Last active January 4, 2023 14:45
SPEED at SCALE breaks EVERYTHING

Scale breaks hardware. Speed breaks software. Speed at Scale breaks everything. -- via @adrianco & @jedberg

@adrianco: "Scale breaks hardware; speed breaks software; Speed At Scale breaks everything" (haha) #flowcon

Netflix: SPEED at SCALE = breaks EVERYTHING. #yow13

@rponte
rponte / sql_generator.sql
Created December 7, 2022 19:04
PostgreSQL: generating sample data
INSERT INTO proposal (
id, address, created_at, "document", email, "name", salary, status, updated_at
)
select
md5(random()::text || clock_timestamp()::text)::uuid as id
,'Rua das Tabajaras, ' || floor(random() * 9999)::int as address
,localtimestamp as created_at
,left(md5(random()::text), 16) as "document"
,left(md5(random()::text), 6) || '@zup.com.br' as email
,'Customer ' || left(md5(random()::text), 22) as "name"
@rponte
rponte / 1-CustomerCreatedEventSqsConsumer.java
Last active January 23, 2025 17:30
Spring Boot: Testing a @SqsListener with TestContainers and LocalStack
package br.com.zup.edu.app2.xxx.samples.aws.sqs;
import br.com.zup.edu.app2.xxx.samples.aws.sqs.model.Customer;
import br.com.zup.edu.app2.xxx.samples.aws.sqs.model.CustomerRepository;
import io.awspring.cloud.messaging.listener.SqsMessageDeletionPolicy;
import io.awspring.cloud.messaging.listener.annotation.SqsListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.messaging.handler.annotation.Header;