Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
fabiolimace / MySimpleHash.java
Last active October 31, 2021 03:48
A simple hash using CRC32 and Adler32 in Java
package com.example;
import java.util.zip.Adler32;
import java.util.zip.CRC32;
public class MySimpleHash {
/**
* Calculate a 64 bits hash by combining CRC32 with Adler32.
*
@fabiolimace
fabiolimace / my_simple_hash.py
Created October 31, 2021 03:46
A simple hash using CRC32 and Adler32 in Python
#!/usr/bin/python3
import zlib
def get_hash(bytes):
return zlib.crc32(bytes) << 32 | zlib.adler32(bytes)
string = "This is a test string"
hash = get_hash(string.encode())
print("output:", hash)
@fabiolimace
fabiolimace / UUIDv3WithNamespace1.java
Created November 1, 2021 09:10
UUID v3 with namespace in Java (examples)
package com.example;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class UUIDv3WithNamespace1 {
/**
@fabiolimace
fabiolimace / LessBlockingFactory.java
Last active November 7, 2021 05:20
A non-blocking factory that wraps an array of time-based UUID factories
package com.github.f4b6a3.uuid.factory;
import java.security.SecureRandom;
import java.util.UUID;
import java.util.function.Supplier;
import com.github.f4b6a3.uuid.enums.UuidVersion;
import com.github.f4b6a3.uuid.factory.function.impl.DefaultRandomFunction;
import com.github.f4b6a3.uuid.factory.nonstandard.PrefixCombFactory;
import com.github.f4b6a3.uuid.factory.rfc4122.RandomBasedFactory;
@fabiolimace
fabiolimace / UploadVersion.java
Last active November 7, 2021 04:39
A utility that generates time-based UUIDs for uploaded files
package com.example;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
@fabiolimace
fabiolimace / README.md
Created December 9, 2021 04:07
Benchmark to compare a fixed pool of SecureRandom to a thread local of SecureRandom in Java

How to prepare the benchmark files on Linux:

BASE="bench"

mkdir $BASE
cp run.sh $BASE/
cp run.bat $BASE/
cp pom.xml $BASE/
cp README.md $BASE/
@fabiolimace
fabiolimace / Docker.md
Last active December 9, 2021 10:42
Docker
@fabiolimace
fabiolimace / README.md
Last active December 9, 2021 08:10
Benchmark to compare `UUID.randomUUID()`, `UuidCreator.getRandomBased()` and others using 4 threads in Java

How to prepare the benchmark files on Linux:

BASE="bench"

mkdir $BASE
cp run.sh $BASE/
cp run.bat $BASE/
cp pom.xml $BASE/
cp README.md $BASE/