Skip to content

Instantly share code, notes, and snippets.

View fabiolimace's full-sized avatar

Fabio Lima fabiolimace

View GitHub Profile
@fabiolimace
fabiolimace / fn_password_md5.sql
Last active April 24, 2020 23:53
Function for generating password MD5 on PostgreSQL
/**
* Returns the password MD5.
*
* @param p_password the password string
* @param p_salt the salt string
* @param p_encode the output encoding: 'base64', 'hex', 'escape'.
*/
CREATE FUNCTION fn_password_md5(p_password VARCHAR, p_salt VARCHAR, p_encode VARCHAR) RETURNS VARCHAR AS $$
DECLARE
v_salt_hash BYTEA := NULL;
@fabiolimace
fabiolimace / find_database_objects.sql
Created June 12, 2020 12:53
Find database objects on PostgreSQL
-- Find table
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE'
AND table_name ILIKE '%tablename%';
@fabiolimace
fabiolimace / RemoveChars.java
Last active July 25, 2020 18:30
Remove chars from a String in Java
package your.package.name;
/**
* Utility class that removes chars from a String.
*
* @author: Fabio Lima 2020
*/
public class RemoveChars {
public static String remove(String string, String remove) {
@fabiolimace
fabiolimace / ReplaceChars.java
Last active July 25, 2020 18:32
Replace chars of a String in Java, equivalent to bash 'tr' and perl 'tr///', aka, transliterate
package your.package.name;
/**
* Utility class that replaces chars of a String, aka, transliterate.
*
* It's equivalent to bash 'tr' and perl 'tr///'.
*
* @author: Fabio Lima 2020
*/
public class ReplaceChars {
@fabiolimace
fabiolimace / hostname-hash-uniqueness.sh
Last active August 20, 2020 10:35
Calculate uniqueness of hostname hashes using SHA256 algorithm
#!/bin/bash
#
# Calculate uniqueness of hostname hashes using SHA256 algorithm
#
# hostname-0001, hostname-0002, hostname-0003...
HOSTNAME_BASE="hostname";
# % of unique hashes for 256 host names: 0.65625000000000000000
USED_NODES=256; # used nodes
@fabiolimace
fabiolimace / TimeUuidCreator.java
Last active October 24, 2020 20:36
Generate time-based and time-ordered UUID in Java
package your.package.name;
import java.security.SecureRandom;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
/**
* A UUID generator that creates time-based and time-ordered UUIDs.
@fabiolimace
fabiolimace / HashUuidCreator.java
Last active October 24, 2020 21:21
Generate name-based UUID in Java
package your.package.name;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
/**
* A UUID generator that creates hash-based or name-based UUIDs (MD5 and SHA-1).
*
@fabiolimace
fabiolimace / RandomUuidCreator.java
Last active October 24, 2020 21:25
Generate random-based UUID in Java
package your.package.name;
import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID;
/**
* A UUID generator that creates random-based UUIDs (UUIDv4)
*
* RFC-4122 compliant.
@fabiolimace
fabiolimace / NanoCombCreator.java
Last active October 24, 2020 22:15
Generate COMB UUID/GUID with nanosecond resolution in Java
package your.package.name;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.UUID;
/**
* A UUID generator that creates a COMB GUID with nanoseconds resolution.
*
* It borrows the main idea from ULID and COMB generators: a concatenation of
@fabiolimace
fabiolimace / file_encoding_examples.sh
Created December 2, 2020 21:38
File encoding examples
# Check file encoding
file -i INPUT_FILE.TXT
INPUT_FILE.TXT: text/plain; charset=utf-8
# Convert from UTF-8 to ISO-8859-1 with transliteration and ignoring invalid characters
iconv -f utf-8 -t iso-8859-1//TRANSLIT -c -o OUTPUT_FILE.TXT INPUT_FILE.TXT