Skip to content

Instantly share code, notes, and snippets.

<?php
declare(strict_types=1);
use Symfony\Component\Yaml\Yaml;
require 'vendor/autoload.php';
$baseline = Yaml::parseFile('.phpstan-baseline.neon');
#!/bin/sh
if [[ -z "$1" ]]; then
echo "Syntax: $0 debfile"
exit 1
fi
DEBFILE="$1"
TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "$DEBFILE" .deb`.modfied.deb
@cs278
cs278 / helpers.php
Created September 3, 2026 11:26
Helpful PHPUnit helpers
<?php
trait HelpersTrait
{
/**
* Execute a callback with a custom error handler for the life of the callback.
*
* This is useful to suppress targeted PHP errors/warnings/notices.
*
* The error handler should return true to suppress an error, false to trigger
$ PHP_VERSION=8.1 php -f test.php
string(10) "2024-01-02"
$ PHP_VERSION=8.2 php -f test.php
string(10) "2024-01-01"
<?php
declare(strict_types=1);
final class MyClass
{
use VendorTrait;
public function __construct(private readonly bool $foo)
{
@cs278
cs278 / gen.php
Created June 11, 2024 23:34
Generate test data for implementing PHP comparisons in userland.
<?php
require 'vendor/autoload.php';
interface Ref
{
public function value();
public function export(): string;
}
@cs278
cs278 / a_composer.json
Last active August 4, 2023 14:08
Composer dependency resolution fun
{
"require": {
"psr/log": "*",
"symfony/console": "=4.4.26 || =5.4.26"
}
}
@cs278
cs278 / test.php
Created August 5, 2022 11:48
Generate mysql truth table
<?php
use Symfony\Component\Process\Process;
require 'vendor/autoload.php';
$comparisons = ['AND', 'OR'];
$expressions = ['NULL', '0', '1'];
$sql = [];
@cs278
cs278 / gist:f7d6ce62fdb18c7fb65d66a3b4a96120
Last active April 15, 2021 13:39
Parse duration in Excel
Parses "1 hour 30 minutes 20 seconds" and similar strings in to a number of seconds.
Replace A21 with the input cell.
=IF(ISERROR(SEARCH("h",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A21,"seconds","s"),"second","s"),"minutes","m"),"minute","m"),"hours","h"),"hour","h")," ",""))),0,VALUE(LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A21,"seconds","s"),"second","s"),"minutes","m"),"minute","m"),"hours","h"),"hour","h")," ",""),SEARCH("h",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A21,"seconds","s"),"second","s"),"minutes","m"),"minute","m"),"hours","h"),"hour","h")," ",""))-1))*3600)+IF(ISERROR(SEARCH("m",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A21,"seconds","s"),"second","s"),"minutes","m"),"minute","m"),"hours","h"),"hour","h")," ",""))),0,VALUE(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A21,"seconds","s"),"second","s"),"minutes",
@cs278
cs278 / searchd.patch
Last active March 6, 2023 15:53
Fix Sphinx Search and MariaDB
--- src/searchd.cpp 2014-01-22 15:37:08.000000000 +0000
+++ src/searchd.cpp 2020-10-06 16:45:05.577703559 +0000
@@ -10164 +10164 @@
- iWarns |= ( SERVER_MORE_RESULTS_EXISTS<<16 );
+ iWarns |= ( 8U<<16 );