Skip to content

Instantly share code, notes, and snippets.

View juanparati's full-sized avatar

Juan Lago juanparati

  • Aarhus (Denmark)
View GitHub Profile
@juanparati
juanparati / colorize.php
Created December 1, 2021 10:31
Color helper function
/**
* Colorize helper.
*/
class Colorize
{
/**
* RGB array for a color.
*
@juanparati
juanparati / StorageOverride.ts
Last active May 1, 2023 12:43
Avoid Session and Local storage quota error overriding the Storage prototype
/**
* Override Localstorage and Sessionstorage setItem prototype
*/
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function(key, value)
{
const isQuotaExceededError = (err: unknown) => err instanceof DOMException &&
(
// Legacy Webkit
@juanparati
juanparati / mariadb_uuidv7.sql
Last active November 14, 2024 19:14
UUID7 generation function for MariaDB
DELIMITER $$
CREATE DEFINER = CURRENT_USER FUNCTION `uuidv7` () RETURNS UUID LANGUAGE SQL NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER
COMMENT 'Generate a UUID7 according to https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#variant_and_version_fields'
BEGIN
-- Obtain date with 4 milliseconds precision
SET @now = sysdate(4);
/*
UNIX_TIMESTAMP returns a 32bits number, so this function will not work after the Epochalypse, I am crossing my fingers and I hope that MySQL/MariaDB teams will move to 64bits timestamps before than 2038.
*/
SET @time_sec = LPAD(HEX(TRUNCATE(UNIX_TIMESTAMP(@now), 0)), 9, '0');
@juanparati
juanparati / uui7_partition_generator.php
Created June 10, 2024 07:25
UUI7 partition generator
<?php
use Ramsey\Uuid\Uuid;
$date = now()->parse("2024-01-01 00:00:00");
while ($date->year < 2039) {
$dateProcess = (clone $date)
->endOfMonth()
->hour(23)
->minute(59)