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 / 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:

@rponte
rponte / CreateNewUserController.java
Last active January 9, 2024 14:37
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 February 7, 2024 02:36
JPA and Hibernate: Simple and Smart way of using PostgreSQL Advisory Locks with JPQL to prevent Lost Update anomaly
package br.com.stackspot.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 October 17, 2023 14:41
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 August 2, 2023 22:08
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"