Skip to content

Instantly share code, notes, and snippets.

@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 / CombUuidCreator.java
Last active July 14, 2023 01:03
Generates COMB UUID/GUID in Java
package your.package.name;
import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID;
/**
* A UUID generator that creates COMB UUIDs.
*
* The COMB UUIDs combine the creation time and random bytes.
@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 / 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 / StringPadding.java
Last active December 8, 2021 08:02
Utility class for left pad, right pad, center pad and zero fill of strings in Java
package com.example;
/**
* Utility class for left pad, right pad, center pad and zero fill.
*
* @author Fabio Lima 2020-2021
*/
public final class StringPadding {
public static String left(String string, int length, char fill) {
@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 / _fix-wifi-intel-z83-mini-pc.sh
Last active October 9, 2025 07:43
Fix Wifi of Intel Z83 mini PC on Ubuntu 20.04
#!/bin/bash
#
# Fix Wifi of Intel Z83 mini PC on Ubuntu 20.04
#
# Download these files in the same folder:
# - brcmfmac43455-sdio.txt
# - brcmfmac43455-sdio.clm_blob.base64
#
# Source:
# https://github.com/Linwood-F/MusicalPi/wiki/Intel-Z83-mini-PC-setup-(still-MusicalPi)
@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 / 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