Skip to content

Instantly share code, notes, and snippets.

@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([
@cs278
cs278 / output.sh
Last active June 10, 2016 10:47
Composer signature bad encoding
$ wget -qO- https://getcomposer.org/download/1.1.2/composer.phar.sig | jq -r '.sha384' | base64 --decode | sha256sum
base64: invalid input
867a94f359e4a8431d8bed267edd85414e1c99acb76fa3686f7167dd143c6c76 -
$ wget -qO- https://getcomposer.org/download/1.1.2/composer.phar.sig | jq -r '.sha384' | php -r 'echo base64_decode(stream_get_contents(STDIN));' | sha256sum
867a94f359e4a8431d8bed267edd85414e1c99acb76fa3686f7167dd143c6c76 -
$ php -a
php > var_dump(hash('sha256', base64_decode('gvW3HhdC4KvSiWOZ/P4pS6C0e39mXRFdLvMIjUxBoxe7YyEe5ueMgEHJ3SLvAbjD4JE4dEw4hqeBY+hFPeSPvBMFcNVPAcYWEnYDCcbc/y3dKMmBWHkl2O4Ahf9YFv6ZNxHQbHkKSlsUAl4x7RL7rgPjJ9NgV7uRwsyyruYg+/RjmastYIJqgK2xWxaVlko5KIFs5QT1/5pJUDo3+9MYXvTvOFQQpoPdhAQ11MWnHVlAx9wX+LqA6biTBB5hSP/P/wcTSelFdKH+XUK20ECQ+1+gwtdFvQfwVfdJP6bcX6/NV3P1aiIOjql7jwD+tJRKCBZjjYS4klHzCA8YM+MK5DNl8yYuW3tGsMshljMEKIhtZJbfUO8gWMHzGn1XADJ6/w6yBhU3OJG7cX7AYZWBVuZxM72PKgxYTnZWwfOo3s9fYIsgAoTI9IBIKu4wgi+twyNfZa0l41ZBpGWvTXbUol/M4mdmAUQrfb+DNviNwekJ8kYj4aX0Uaz/pC61ZEA8YRvIje8FlJqtTFJdlzBtTDW
@cs278
cs278 / gist:7e60c231159bc2249cd8
Created June 26, 2015 10:25
Composer SSH multiplexing timeout (#4180)
chris.smith@wp-040-du:/tmp/test $ ssh -V; ssh github.com; ssh -O exit github.com; ssh -O exit github.com
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2, OpenSSL 1.0.1f 6 Jan 2014
Hi cs278! You've successfully authenticated, but GitHub does not provide shell access.
Exit request sent.
Control socket connect(/home/chris.smith/.ssh/sockets/wp-040-du-git@github.com:22): No such file or directory
chris.smith@wp-040-du:/tmp/test $ composer require -vvv --profile --prefer-source psr/log '*'
[4.3MB/0.01s] Reading ./composer.json
[4.5MB/0.01s] Loading config file /home/chris.smith/.config/composer/config.json
[4.5MB/0.01s] Loading config file /home/chris.smith/.config/composer/auth.json
[4.5MB/0.01s] Loading config file ./composer.json
@cs278
cs278 / gist:a3a96af7bed205e18007
Last active August 29, 2015 14:15
Xubuntu setup

Cleanup

apt-get purge thunderbird*
apt-get purge firefox* xul-*
apt-get purge gnumeric*
apt-get purge abiword*
apt-get purge pidgin* libpurple*
apt-get purge gmusicbrowser
apt-get purge transmission*