Skip to content

Instantly share code, notes, and snippets.

View twysto's full-sized avatar
😀
Enthusiastic

Loïc Liné twysto

😀
Enthusiastic
View GitHub Profile
@twysto
twysto / index.php
Last active March 26, 2025 15:05
PHP | Flip an integer or a boolean to its opposite value
<?php
function flip(int|bool $val): int|bool
{
$output = $val ^ 1;
settype($output, gettype($val));
return $output;
}
@twysto
twysto / index.php
Last active February 17, 2025 09:29
Extract text content from HTML
<?php
if (! function_exists('extractTextContentFromHTML')) {
/**
* Extract text content from HTML.
* This is certainly perfectible, but it works well in most situations.
*
* @see https://regex101.com/r/3nbq1R/1
*
* @param string $html
@twysto
twysto / CRC32.js
Last active December 10, 2024 11:18
CRC32 class using Vanilla JS
/**
* Calculate CRC32 unsigned for 0x04C11DB7 polynomial.
* Browser and NodeJS compatible version.
*
* Usage:
*
* const crc = new CRC32();
* console.log(crc.calculate('hello crc32'));
*/
class CRC32 {
@twysto
twysto / README.md
Last active October 29, 2024 15:07
Install Apache Cassandra 5.0.2 as a Tarball binary file + Quickstart
@twysto
twysto / index.php
Last active October 29, 2024 15:07
Example usage of the "Null Coalescing Assignment Operator"
<?php
$arr = [
'a' => 'xyz',
'b' => null,
'c' => 0,
];
// Rather than writing:
//
@twysto
twysto / HOWTO.md
Last active March 13, 2024 11:05
Homestead - Regenerate SSL Certificates
  1. If the folder /etc/ssl/.old-certs doesn't exists, create it:
sudo mkdir /etc/ssl/.old-certs
  1. Move old certs files into it:
sudo mv /etc/ssl/certs/phpmyadmin.local.{cnf,crt,csr,key} /etc/ssl/.old-certs
@twysto
twysto / README.md
Last active March 27, 2025 13:42
Année bisextile
@twysto
twysto / gist:23790adc965e5c9c278f19e7ab702bb8
Created November 15, 2023 10:02
Ubuntu default browser from Firefox (default) to Brave
First, check if the `brave.desktop` file is present in `/usr/share/applications`.
If not, just create a symlink like that:
```
ln -s /snap/brave/current/meta/gui/brave.desktop /usr/share/applications/brave.desktop
```
Then edit the `default.list` file:
```
sudo nano /usr/share/applications/defaults.list
```
@twysto
twysto / array_weave.php
Last active February 22, 2024 15:57
PHP | Array Weaving
<?php
if (! function_exists('array_weave')) {
function array_weave(...$args) {
/**
* @todo
* 1. Check that each argument is the same size. If they're not, return false.
* 2. Add the type declarations and corresponding DocBlock.
*/
return array_map(fn (...$args) => func_get_args(), ...$args);
@twysto
twysto / spreg_match.php
Last active March 31, 2023 10:08
PHP: Safe PCRE Regex Match `spreg_match(...)`
<?php
if (! function_exists('spreg_match')) {
function spreg_match(
string $pattern,
string $subject,
array &$matches = null,
int $flags = 0,
int $offset = 0
): ?string {