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 / HealthCheckerService.kt
Created January 15, 2021 17:58
GRPC: simple example of GRPC Health Checking Protocol
package br.com.zup.edu
import io.grpc.health.v1.HealthCheckRequest
import io.grpc.health.v1.HealthCheckResponse
import io.grpc.health.v1.HealthGrpc
import io.grpc.stub.StreamObserver
import javax.inject.Singleton
@Singleton
class HealthCheckerService: HealthGrpc.HealthImplBase() {
@rponte
rponte / CustomGrpcServerHealthIndicator.kt
Last active January 26, 2021 12:49
GRPC: simple and dirty bugfix on Micronaut GrpcServerHealthIndicator
package br.com.zup.edu.bugfix;
import io.micronaut.context.annotation.Replaces;
import io.micronaut.core.async.publisher.AsyncSingleResultPublisher;
import io.micronaut.grpc.server.GrpcEmbeddedServer;
import io.micronaut.grpc.server.health.GrpcServerHealthIndicator;
import io.micronaut.health.HealthStatus;
import io.micronaut.management.health.indicator.HealthResult;
import org.reactivestreams.Publisher;
@rponte
rponte / using-uuid-as-pk.md
Last active November 18, 2025 16:11
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 / sync_clock.sh
Created December 14, 2020 01:55
WSL2: keep in sync clock between Windows and WSL2
sudo hwclock -s
@rponte
rponte / encryptor.sql
Last active May 15, 2023 13:54
PostgreSQL: encrypting and decrypting (and Rails examples)
-- first, install the pgcrypto module
CREATE EXTENSION pgcrypto;
-- this is how to use its crypto-functions and encoding the value into base64 (by default postgresql uses bytea)
with sensitive_info (email, encrypted_email) as (
values ('[email protected]', 'ww0EBwMC1V/tU6ZYV3Nq0kEBz8iqdRYE0A/zL3dQ+du9Ex+GkSDzz3Llq8g1yCoa9XpNbhKzK7U5
b1EtUYzUMer8XSaCwdFSPKmbSfJo1btoSQ==')
)
select encode(pgp_sym_encrypt(s.email, 'mySecretKey'), 'base64') as encrypted_data
,pgp_sym_decrypt(decode(s.encrypted_email, 'base64'), 'mySecretKey') as decrypted_data
@rponte
rponte / TLVParser.java
Last active July 13, 2025 17:48
Example of a simple TLV parser (decoder)
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Class responsible for parsing an encoded-text in TLV (Tag-Length-Value) format
*/
public class TLVParser {
@rponte
rponte / docker-compose.yml
Created June 17, 2020 20:11
Docker-compose: PostgreSQL and PgAdmin
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: "postgres:10.6"
restart: always
ports:
- 5432:5432
environment:
@rponte
rponte / postgresql-new-user.sql
Last active June 17, 2020 20:14
PostgreSQL: Creating a new user and database
-- Create the database user
CREATE USER rponte WITH PASSWORD '123';
-- Create the database
CREATE DATABASE mydb WITH OWNER = rponte
ENCODING = 'UTF8'
LC_CTYPE = 'en_US.UTF-8'
LC_COLLATE = 'en_US.UTF-8'
TEMPLATE = template0;
@rponte
rponte / gist:8d82b218db4021816e990e9a940777d2
Created May 21, 2020 22:18 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t