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 / Robustness_principle
Created May 11, 2011 00:15
Postel's Law - Robustness Principle
"Be conservative in what you send; be liberal in what you accept."
http://en.wikipedia.org/wiki/Robustness_principle
- Tolerant Reader by Martin Fowler
http://martinfowler.com/bliki/TolerantReader.html
@rponte
rponte / using-uuid-as-pk.md
Last active March 21, 2024 12:26
Não use UUID como PK nas tabelas do seu banco de dados

Pretende usar UUID como PK em vez de Int/BigInt no seu banco de dados? Pense novamente...

TL;TD

Não use UUID como PK nas tabelas do seu banco de dados.

Um pouco mais de detalhes

@rponte
rponte / notes-on-rate-limiting-strategies-techniques.md
Last active March 20, 2024 09:44
Notes on Gloogle Cloud Rate-limiting strategies and techniques

Gloogle Cloud: Rate-limiting strategies and techniques

Sever-side

  • Even in the cases where the rate limiting is implemented entirely on the server side, the client should be engineered to react appropriately.
  • Decisions about failing open or failing closed are mostly relevant on the server side, but knowledge of what retry techniques the clients use on a failed request might influence your decisions made about server behavior.
  • In HTTP services, the most common way that services signal that they are applying rate limiting is by returning a 429 status code in the HTTP response. A 429 response can provide additional details about why the limit is applied (for example, a freemium user has a lower quota, or the system is undergoing maintenance).
  • Build your system with robust error handling in case some part of your rate-limiting strategy fails, and understand what users of your service will receive in those situations. [...] U
@rponte
rponte / get-latest-tag-on-git.sh
Last active March 11, 2024 07:50
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@rponte
rponte / 1-CustomerCreatedEventSqsConsumer.java
Last active March 6, 2024 02:19
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;
// Adding js script dynamically into page..
script = document.createElement("script");
script.src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
document.body.appendChild(script);
@rponte
rponte / build.gradle
Last active February 20, 2024 06:44
Configuring Gradle compiler encoding
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
eclipseJdt << {
ant.propertyfile(file: ".settings/org.eclipse.core.resources.prefs") {
ant.entry(key: "eclipse.preferences.version", value: "1")
ant.entry(key: "encoding/<project>", value: "utf-8")
@rponte
rponte / avoid-distributed-transactions.md
Last active February 15, 2024 14:17
THEORY: Distributed Transactions and why you should avoid them (2 Phase Commit , Saga Pattern, TCC, Idempotency etc)

Distributed Transactions and why you should avoid them

  1. Modern technologies won't support it (RabbitMQ, Kafka, etc.);
  2. This is a form of using Inter-Process Communication in a synchronized way and this reduces availability;
  3. All participants of the distributed transaction need to be avaiable for a distributed commit, again: reduces availability.

Implementing business transactions that span multiple services is not straightforward. Distributed transactions are best avoided because of the CAP theorem. Moreover, many modern (NoSQL) databases don’t support them. The best solution is to use the Saga Pattern.

[...]

@rponte
rponte / ResourceServerConfig.java
Last active February 7, 2024 02:39
Spring Security: example of OAuth2 Resource Server configuration (Spring Boot v2.6.7)
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;