Skip to content

Instantly share code, notes, and snippets.

View fabiolimace's full-sized avatar

Fabio Lima fabiolimace

View GitHub Profile
@fabiolimace
fabiolimace / record-system-output-audio.sh
Last active April 20, 2024 08:06
Record system output audio with FFMPEG on Ubuntu Linux
#!/usr/bin/bash
#
# Records the oudio from your browser and other applications.
#
# USAGE:
#
# record-system-output-audio.sh DURATION
#
# Where DURATION is [<HH>:]<MM>:<SS> or <SS>[s] (read ffmpeg-utils manual)
#
@fabiolimace
fabiolimace / snowflake-id.sql
Created April 18, 2024 20:13 — forked from beginor/snowflake-id.sql
Twitter Snowflake ID for PostgreSQL
CREATE SEQUENCE public.global_id_seq;
ALTER SEQUENCE public.global_id_seq OWNER TO postgres;
CREATE OR REPLACE FUNCTION public.id_generator()
RETURNS bigint
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
@fabiolimace
fabiolimace / block-site-add.sh
Last active April 11, 2024 01:38
Block sites in /etc/hosts
#!/usr/bin/bash
#
# Removes a block to /etc/hosts.
#
# USAGE:
#
# $ block-site-add.sh EXAMPLE.COM
# 0.0.0.0 example.com
# 0.0.0.0 www.example.com
#
@fabiolimace
fabiolimace / Entity.java
Last active April 3, 2024 20:36 — forked from rajivrnair/Entity.java
Custom Hibernate UUID Generator
// Before
@Id
@Column(name = "entity_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
private String entityId;
// After
@Id
@Column(name = "entity_id")
@fabiolimace
fabiolimace / Id.java
Last active March 2, 2024 02:45
Strongly Typed Identifier using ULID Creator
package com.example.idapi;
import java.util.Objects;
import com.github.f4b6a3.ulid.Ulid;
import com.github.f4b6a3.ulid.UlidCreator;
public abstract class Id<T extends Id<T>> implements Comparable<T> {
protected final Ulid value;
@fabiolimace
fabiolimace / LazyLoader.java
Last active February 25, 2024 13:15
Lazy loader class Java
private static class Lazy<T> {
private T object = null;
private Supplier<T> supplier;
private static final ReentrantLock lock = new ReentrantLock();
public Lazy(Supplier<T> supplier) {
this.supplier = supplier;
}
@fabiolimace
fabiolimace / UUIDv7.SQLite.sql
Created February 14, 2024 00:55
UUIDv7 for SQLite
-- UUIDv7 canonical format: AAAAAAAA-BBBB-7CCC-DDDD-EEEEEEEEEEEE
select printf('%08x', ((strftime('%s') * 1000) >> 16)) || '-' ||
printf('%04x', ((strftime('%s') * 1000) + ((strftime('%f') * 1000) % 1000)) & 0xffff) || '-' ||
printf('%04x', 0x7000 + abs(random()) % 0x0fff) || '-' ||
printf('%04x', 0x8000 + abs(random()) % 0x3fff) || '-' ||
printf('%012x', abs(random()) >> 16);
@fabiolimace
fabiolimace / run_test_uuid.sh
Created February 4, 2024 00:55 — forked from ardentperf/run_test_uuid.sh
UUID benchmark driver script
#!/bin/bash
INIT_TABLE_ROWS=20000000
PGBENCH_TRANSACTIONS_PER_CLIENT=100000
PGBENCH_CLIENTS=10
run_test() {
echo "$(date +%y%m%d.%H%M) STARTING TEST $1"
pg_stop
@fabiolimace
fabiolimace / notes.sh
Created January 15, 2024 05:45
Append notes to today's text file in the notes folder
#!/bin/bash
#
# Append notes to today's text file in the notes folder.
#
# Usage:
#
# $ notes # append to today's file
# this is a note
# [CTRL+D]
#
@fabiolimace
fabiolimace / ThreadLocalWeakRefTest.java
Created December 14, 2023 23:09 — forked from chrisvest/ThreadLocalWeakRefTest.java
ThreadLocals and weak references
import org.junit.Test;
import java.lang.ref.WeakReference;
import static org.junit.Assert.assertNull;
public class ThreadLocalWeakRefTest {
/**
* Many Java web servers and containers go out of their way to find and null
* out ThreadLocals that an application might have created. Question is, is