Skip to content

Instantly share code, notes, and snippets.

@sfaut
sfaut / SimplePivoter.php
Created March 23, 2024 16:16
PHP pivots an array of records to an array of series or an array of series to an array of records
<?php
/*
Utility class that pivots an array of records to an array of series
or an array of series to an array of records
Author : sfaut <https://github.com/sfaut>
Publication date : 2024-03-23
Tested with PHP 8.3.3
*/
@sfaut
sfaut / gist:a5a83571420f857906eb5e69c6401dfe
Created July 9, 2023 18:19 — forked from digitaljhelms/gist:4287848
Git/GitHub branching standards & conventions

Branching

Quick Legend

Description, Instructions, Notes
Instance Branch
@sfaut
sfaut / array_pivot.php
Created April 9, 2023 10:31
PHP pivots an array of records
/*
Pivots an array of records
Author : sfaut <https://github.com/sfaut>
Publication date : 2023-04-09
Tested with PHP 8.2.4
*/
function array_pivot(array $data, string $key_rows, string $key_columns, string $key_values, mixed $default_value = null): array
{
// Transtyping
@sfaut
sfaut / REGEXP_COUNT.sql
Created April 2, 2023 14:32
This REGEXP_COUNT() MySQL implementation returns the number of times pattern is matched in expression
-- Returns the number of times pattern is matched in expression
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2023-04-02
-- Tested with MySQL 8.0.32 (@@sql_mode='ANSI,TRADITIONAL')
DELIMITER ;;
CREATE FUNCTION "REGEXP_COUNT"(expression TEXT, pattern TEXT)
RETURNS INT UNSIGNED
DETERMINISTIC
@sfaut
sfaut / RANDOM_INTEGER.sql
Created March 11, 2023 16:51
Get a random integer between start and stop excluded
-- Get a random integer between start and stop excluded
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2023-03-11
-- Tested with MySQL 8.0.32 (@@sql_mode='ANSI,TRADITIONAL')
CREATE FUNCTION RANDOM_INTEGER(start INT, stop INT)
RETURNS INT
NOT DETERMINISTIC
NO SQL
COMMENT 'Get a random integer between start and stop excluded'
@sfaut
sfaut / FROM_SECONDS.sql
Created March 4, 2023 23:58
Converts a number of seconds since year 0 to a DATETIME
-- Converts a number of seconds since year 0 to a DATETIME
-- MySQL counterpart of TO_SECONDS() : https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_to-seconds
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2023-03-05
-- Tested with MySQL 8.0.32 (@@sql_mode='ANSI,TRADITIONAL')
CREATE FUNCTION FROM_SECONDS(seconds BIGINT)
RETURNS DATETIME
DETERMINISTIC
COMMENT 'Converts a number of seconds since year 0 to a DATETIME'
@sfaut
sfaut / ANSI.md
Created February 3, 2023 21:39 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@sfaut
sfaut / REMOVE_DIACRITICS.sql
Last active April 2, 2023 14:17
Removes diacritics from input string
-- Removes diacritics from input string
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2023-01-07
-- Tested with MySQL 8.0.31 (@@sql_mode='ANSI,TRADITIONAL')
DELIMITER ;;
CREATE FUNCTION REMOVE_DIACRITICS(input TEXT) RETURNS TEXT CHARSET utf8mb4
DETERMINISTIC
COMMENT 'Removes diacritics from input string'
@sfaut
sfaut / polygon-svg.php
Last active January 9, 2023 07:15
Creates a polygon SVG with n vertices and a top apex
<?php
// Author : sfaut <https://github.com/sfaut>
// Publication date : 2022-09-06
// Usage :
// <img src="polygon-svg.php?vertices=5" alt="A SVG pentagon!">
$vertices = (int)$_GET['vertices'] ?? 5;
@sfaut
sfaut / hsl.sql
Last active September 5, 2022 20:00
HSL management with MySQL
-- HSL functions, manage HSL CSS colors
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2022-09-05
-- Tested with MySQL 8.0.30 (@@sql_mode='ANSI,TRADITIONAL')
/*
Summary :
hsl() Create a CSS HSL representation of a color