Skip to content

Instantly share code, notes, and snippets.

$ 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 );
@cs278
cs278 / instructions.md
Last active July 25, 2022 18:19
Compile Symfony cache on Platform.sh at build time

Compile Symfony cache at build time

This modification to your Symfony application allows the cache to be warmed at the time Platform.sh builds your application container. The usual advice is to warm the cache in the deploy hook, which can result in ~1 minute of downtime waiting for the cache. Given Symfony’s cache is compiled once and only needs updating if your application code changes, which is impossible on Platform.sh, this allows deployment downtime to be reduced to less than a second.

Assumptions

@cs278
cs278 / 0.4.8_0.4.9.diff
Created August 2, 2017 15:26
Web Developer 0.4.9 toolbar hacked
diff '--unified=3' --recursive 0.4.8_0/background/javascript/background.js 0.4.9_0/background/javascript/background.js
--- 0.4.8_0/background/javascript/background.js 2017-03-15 10:38:38.650194261 +0000
+++ 0.4.9_0/background/javascript/background.js 2017-08-02 14:18:29.679041517 +0100
@@ -1,3 +1,16 @@
+console.log("Start");
+
+chrome.runtime.onInstalled.addListener(function(details) {
+ console.log("onInstalled");
+ if(details.reason == "install") {
+ console.log("This is a first install!");
@cs278
cs278 / broken.md
Last active July 21, 2016 16:19
Platform.sh Symfony broken

Symfony caches all configuration parameters so even changing the varaible will not rebuild the cache and if you manually rebuild the cache it takes a good second to complete.

PR to add fetching of variables directly from the environment is in the works: symfony/symfony#18155

<?php

echo base64_encode(json_encode([