Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
fabiolimace / ObjectPool.java
Last active December 12, 2021 07:18
Object Pool in Java
package com.example;
// Read: https://sourcemaking.com/design_patterns/object_pool
public abstract class ObjectPool<T> {
public static final int SIZE = 32;
// private fields of the object pool
private final Object[] pool = new Object[SIZE];
private final boolean[] lock = new boolean[SIZE];
@fabiolimace
fabiolimace / sqlite_tsid.sql
Last active December 21, 2021 07:57
Time Sortable ID for SQLite
-- 86400000: `24 * 60 * 60 * 1000`
-- 2458849.5: `julianday('2020-01-01')`
SELECT CAST((JULIANDAY('now') - 2458849.5) * 86400000 AS INTEGER) << 22 | (RANDOM() & 0x3fffff);
@fabiolimace
fabiolimace / pdf-to-epub.sh
Last active December 31, 2021 22:38
Converter um livro em formato PDF para o formato ePUB
#!/bin/bash
# Converte um livro em formato PDF para o formato ePUB
# Parametros
LIVRO="meu-livro"
TITULO="Meu Livro"
# Converter o PDF para TEXTO
pdftotext ${LIVRO}.pdf ${LIVRO}.txt
@fabiolimace
fabiolimace / ksuid.sql
Last active September 21, 2025 04:09
Functions for generating Segment's KSUIDs on PostgreSQL
/*
* MIT License
*
* Copyright (c) 2023 Fabio Lima
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@fabiolimace
fabiolimace / convert_ulid_to_uuid.py
Last active September 15, 2022 00:59
Convert ULID to and from UUID in Python
#!/bin/env python3
# @author: Fabio Lima
# @created: 2022-02-10
base16 = '0123456789abcdef'
base32 = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
def encode(number, alphabet):
text = ''
radix = len(alphabet)
@fabiolimace
fabiolimace / remover-acentos.sh
Created February 20, 2022 02:07
Remover acentos de arquivo de texto
#!/bin/bash
cat "${1}" | tr 'áàâãéèêẽíìîĩóòôõúùûũçÁÀÂÃÉÈÊẼÍÌÎĨÓÒÔÕÚÙÛŨ' 'aaaaeeeeiiiioooouuuucAAAAEEEEIIIIOOOOUUUU'
@fabiolimace
fabiolimace / batchrename.sh
Created February 20, 2022 02:09
Batch rename - renomear arquivos em lote
#!/bin/bash
# Rename a list of files.
#
# author: Fabio Lima
# date: 2014-06-19
#
# HOW TO USE:
# shell > batchrename LIST FORMAT
# - LIST: a list of file to be removed.
# - FORMAT: format for the files names.
@fabiolimace
fabiolimace / contatempo.sh
Created February 20, 2022 02:11
Conta tempo - contagem de tempo de execução de um comando
#!/bin/bash
COMANDO=""
INICIO=0;
FIM=0;
INTERVALO=0;
HOR=0;
MIN=0;
SEG=0;
SUCESSO=0;
@fabiolimace
fabiolimace / copiaunica.sh
Created February 20, 2022 02:13
Copia unica - Copia diretorios recurivamente assegurando que seus arquivos nao serao repetidos
#!/bin/bash
# Copia diretorios recurivamente assegurando
# que seus arquivos nao serao repetidos
#
# MODO DE USAR:
# shell > copiaunica DIRETORIO_ORIGEM DIRETORIO_DESTINO
#
N=0;
TOTAL=0;