Sand Fox
-
Ignoring SSL Errors in Chrome
Very useful when you are developing anything WebAuthn related.
--ignore-certificate-errors
will disable any SSL warnings like self-signed certs.--user-data-dir
will isolate this unsafe Chrome instance from your regular browsing. -
Generating UUIDv7 in PostgreSQL
But what about Postgres? We can do it too. Hopefully generators for new UUID versions will be added to uuid-ossp but it is not yet the case.
The easiest way for now is to use pgcrypto, so let's start with that:
Now port the solution from the MySQL post:
select lpad(to_hex((extract(epoch from now()) * 1000)::bigint), '12', '0') || '7' || -- version substr(encode(gen_random_bytes(2), 'hex'), 2) || to_hex((floor(random() * 4) + 8)::int) || -- variant bits substr(encode(gen_random_bytes(8), 'hex'), 2) as uuid;
Like with MariaDB, Postgres doesn't care about dashes on insertion, so this value can be directly applied to a field with the uuid type.
And again, to make it a formatted value, use a type cast:
select (lpad(to_hex((extract(epoch from now()) * 1000)::bigint), '12', '0') || '7' || substr(encode(gen_random_bytes(2), 'hex'), 2) || to_hex((floor(random() * 4) + 8)::int) || substr(encode(gen_random_bytes(8), 'hex'), 2))::uuid as uuid;
And to have a bytea value, use decode:
-
Generating UUIDv7 in MySQL and MariaDB
A quick way to generate UUIDv7 in MySQL 8 and MariaDB 11:
select concat( -- Use NOW(3) to get milliseconds lpad(hex(unix_timestamp(now(3)) * 1000), 12, '0'), '7', -- version substr(hex(random_bytes(2)), 2), hex(floor(rand() * 4 + 8)), -- variant bits substr(hex(random_bytes(8)), 2) ) as uuid;
This will generate a hex string that can be inserted into MariaDB's UUID type as is, dashes will be added automatically.
If you need it as a binary value, wrap with unhex:
select unhex(concat( lpad(hex(unix_timestamp(now(3)) * 1000), 12, '0'), '7', substr(hex(random_bytes(2)), 2), hex(floor(rand() * 4 + 8)), substr(hex(random_bytes(8)), 2) )) as uuid;
If you specifically need a valid RFC 4122 string representation, use a bin formatter function (MySQL) or a type cast (MariaDB):
-- MySQL select bin_to_uuid(unhex(concat( lpad(hex(unix_timestamp(now(3)) * 1000), 12, '0'), '7', substr(hex(random_bytes(2)), 2), hex(floor(rand() * 4 + 8)), substr(hex(random_bytes(8)), 2) ))) as uuid; -- MariaDB select cast((concat( lpad(hex(unix_timestamp(now(3)) * 1000), 12, '0'), '7', substr(hex(random_bytes(2)), 2), hex(floor(rand() * 4 + 8)), substr(hex(random_bytes(8)), 2) )) as uuid) as uuid;
-
De-hybridize Torrent
A feature that may be desired for some anti-V2 trackers. While I would like to see the torrent community going the other way around, some trackers choose not to allow version 2 torrents and sometimes even hybrids.
The torrent file library now allows cleaning unnecessary or undesired metadata versions from a torrent file.
The intended use and the primary future scope is actually the other way around: the ability to remove version 1 metadata to make use of easy mutability of version 2 torrents to add or remove files in existing torrent structures.
-
PHP Requirements on Packagist
A followup for the previous post: the minimum required PHP versions in packages on the Packagist.
-
How to Choose a Minimum PHP Requirement
As a library developer I often face a problem what should be a minimum PHP requirement. Here are some of my principles.
-
Running 32-bit Images in GitLab CI
A thing that was not obvious to me and relatively hard to google was a way to run a 32-bit docker image in the GitLab CI. Docker itself has
--platform
param but it is not exposed to the.gitlab-ci.yml
file.Luckily it's easy for the official Docker registry. Apart from auto-selection images, it also contains per-architecture image repos with distinct package names. You only need to specify a desired architecture prefix: like
amd64/php
ori386/php
.Example:
.test: script: - composer update - vendor/bin/phpunit test-64bit: extends: .test stage: test image: amd64/php:8 test-32bit: extends: .test stage: test image: i386/php:8
or using the matrix:
-
UUID Library (and ULID to UUID migration)
I created a UUID and ULID library with Doctrine support. Well, who didn't :D
The main scenario for myself was a possible migration for a project from ULIDs to UUIDs since UUIDs got a little bit of support in MySQL 8.
Example code:
<?php use Arokettu\Uuid\UuidParser; // Just a random ULID $ulid = UuidParser::fromBase32('01H44RDYXJPFCF895N3BBXCZRC'); var_dump($ulid->isUuidV7Compatible()); // false // UnexpectedValueException: This ULID cannot be converted to UUID v7 losslessly // $uuid = $ulid->toUuidV7(); $uuid = $ulid->toUuidV7(lossy: true); // note digit 13 becoming '7' and digit 17 moving into [89ab] range var_dump($uuid->toString()); // 01890986-fbb2-73d8-b424-b51ad7d67f0c var_dump($ulid->toRfc4122()); // 01890986-fbb2-b3d8-f424-b51ad7d67f0c var_dump($uuid->toBase32()); // 01H44RDYXJEFCB895N3BBXCZRC var_dump($ulid->toString()); // 01H44RDYXJPFCF895N3BBXCZRC
-
Building 32-bit PHP on 64-bit Fedora
-
Resizing small EFI partition
It started with the firmware failing to update because the EFI partition was low on free space. (Dell, why do you need 70 MB on the EFI while also making it as small as 150 MB at the same time?) Well, resizing the partition is the obvious solution except it ended in a wonderful error message:
(spoiler: they're not)
In my case the GPT partition was resized, just the filesystem was not grown, I only needed to reformat it.