Skip to content

Instantly share code, notes, and snippets.

View theking2's full-sized avatar
🎯
contemplating the odds

Johannes kingma theking2

🎯
contemplating the odds
View GitHub Profile
@theking2
theking2 / read-json-body.php
Last active June 17, 2024 16:50
read json body in php
<?php
$request = json_decode( file_get_contents( 'php://input' ) );
@theking2
theking2 / my.ini
Created June 6, 2024 10:11
charset/collation mariadb
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_520_ci
@theking2
theking2 / call-sp.inc.php
Created June 5, 2024 18:41
call sp and return the last paramete
function call_sp( \mysqli|\PDO $db, string $sp_name, ...$params ): string
{
$placeholders = array_fill( 0, count( $params ), "?" );
$placeholders[] = "@__newid;
$sql = "CALL $sp_name( " . implode( ", ", $placeholders ) . " );";
try {
LOG->debug( "calling Stored Procedure", [ "sql" => $sql ] );
if( $db instanceof \mysqli ) {
@theking2
theking2 / NotificationAlert.js
Last active June 5, 2024 11:14
JavaScript class for notifications
/**
* class Notifications asks for notification
*/
class NotificationAlert {
constructor() {
this.#askNotificationPermission();
}
/**
* ask permissions for Notification, if not granted use alerts
*/
@theking2
theking2 / plugin_class.php
Created May 11, 2024 15:12
WordPress Bootstrap function to load actions and filters
<?php declare(strict_types=1);
abstract class PluginName
{
public function __construct()
{
$this->bootstrap();
}
private function bootstrap()
@theking2
theking2 / regexp_search.md
Last active January 26, 2025 19:10
Replace array() by []
what how
Search ([\s\r\n]*)array[\s\r\n]*\(([\s\r\n]*[^()\s](?:[^()]*[^()\s])?[\s\r\n]*)\)
Replace $1[$2]

Perhaps repeat for nested arrays

@theking2
theking2 / index.php
Created May 8, 2024 07:29
Export stored procedures and function for easy versioning
<?php declare(strict_types=1);
define('NO_SESSION', true);
define('NO_AUTH', true);
require "../inc/config.inc.php";
function show_routine(string $type, string $name) {
global $db;
$query = "SHOW CREATE $type `$name`";
$result = $db->query( $query );
foreach( $result as $row ) {
@theking2
theking2 / git-clone.reg
Created April 18, 2024 13:14
Clone here
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\git-clone]
@="Clone here"
[HKEY_CLASSES_ROOT\Directory\shell\git-clone\command]
@="Powershell -NoProfile -Command \"Set-Location -LiteralPath '%V' ; git clone $(Get-Clipboard)\""
@theking2
theking2 / sql
Created March 30, 2024 16:10
BIN_TO_UUID
CREATE FUNCTION `BIN_TO_UUID`(b binary(16))
RETURNS char(36) CHARSET ascii
BEGIN
DECLARE hexStr CHAR(32);
SET hexStr = HEX(b);
RETURN LOWER(CONCAT(
SUBSTR(hexStr, 25, 12), '-',
SUBSTR(hexStr, 21, 4), '-',
SUBSTR(hexStr, 13, 4), '-',
SUBSTR(hexStr, 17, 4), '-',
@theking2
theking2 / sql
Created March 30, 2024 16:09
UUID_TO_BIN
CREATE FUNCTION `UUID_TO_BIN`(uuid char(36))
RETURNS binary(16)
BEGIN
RETURN UNHEX( CONCAT(
SUBSTRING(uuid, 25, 12),
SUBSTRING(uuid, 20, 4),
SUBSTRING(uuid, 15, 4),
SUBSTRING(uuid, 10, 4),
SUBSTRING(uuid, 1, 8)
));