Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile
@rponte
rponte / AddsAccessTokenHeaderMockMvcConfigurer.java
Created May 20, 2022
Spring Security: Adding Access Token in all requests via MockMvcBuilderCustomizer
View AddsAccessTokenHeaderMockMvcConfigurer.java
package br.com.zup.edu.livraria;
import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcBuilderCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
@rponte
rponte / ResourceServerConfig.java
Last active May 14, 2022
Spring Security: example of OAuth2 Resource Server configuration (Spring Boot v2.6.7)
View ResourceServerConfig.java
package br.com.zup.edu.minhasfigurinhas;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
@rponte
rponte / Album.java
Created Apr 12, 2022
JPA and Hibernate: Bean validation error when merging a transient entity
View Album.java
@Entity
public class Album {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(min = 1)
@OneToMany(cascade = {
@rponte
rponte / reset-network.sh
Last active Feb 8, 2022
WSL2: resetting network (WSL2 DNS issue)
View reset-network.sh
##
# 1. run theses commands on PowerShell as admin
# 2. restart windows
##
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
@rponte
rponte / messaging-and-eventing-platforms.md
Created Jan 21, 2022 — forked from clemensv/messaging-and-eventing-platforms.md
Elements of Messaging and Eventing Platforms
View messaging-and-eventing-platforms.md
title
Elements of Messaging and Eventing Platforms

This document provides a brief overview of the essential elements of a messaging and eventing platform and how they relate to each other.

Message and Event Broker Categories

@rponte
rponte / CacheStore.java
Last active Nov 19, 2021
Simple CacheStore using Guava Cache
View CacheStore.java
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
public class CacheStore {
@rponte
rponte / parametros-jvm-heap-metaspace-gc.md
Last active Dec 5, 2021
Conhecendo e setando parâmetros da JVM
View parametros-jvm-heap-metaspace-gc.md

Conhecendo e setando parâmetros da JVM

Material de suporte rápido para conhecer e setar parâmetros de JVM mais comuns relacionados a propriedades da JVM, configuração de frameworks e libs, aplicação e tuning de memória heap e metaspace, além da definição do algoritimo de GC e algumas configurações para troubleshooting.

Introdução

Todos os comandos aqui são executados via linha de comando, mas podem ser definidos na sua IDE, variável de ambiente (JAVA_OPTS) ou no seu servidor de integração contínua (CI).

Rodando uma aplicação (jar):

@rponte
rponte / CustomExceptionHandler.java
Created Oct 7, 2021
Spring Boot: custom and simple exception handler (using the default payload generated by Spring)
View CustomExceptionHandler.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import java.time.LocalDateTime;
import java.util.Map;
@rponte
rponte / modern-unix.md
Created Aug 3, 2021
Modern Unix: ferramentas de linha de comando uteis
View modern-unix.md
@rponte
rponte / Proposal.kt
Last active Apr 10, 2022
JPA and Hibernate: best way to mapping a primary key as UUID in MySQL 8.x
View Proposal.kt
@Entity
class Proposal(
val name: String,
//
@Column(columnDefinition = "binary(16)") // this works but uses a MySQL's specific type
val customerId: UUID
) {
@Id
@GeneratedValue