Skip to content

Instantly share code, notes, and snippets.

View amnuts's full-sized avatar

Andrew Collington amnuts

View GitHub Profile
amnuts / aspect-ratio.php
Last active October 16, 2023 18:43
Aspect ratio from width/height
function ratio($a, $b)
$gcd = function($a, $b) use (&$gcd) {
return ($a % $b) ? $gcd($b, $a % $b) : $b;
$g = $gcd($a, $b);
return $a/$g . ':' . $b/$g;
amnuts / Dockerfile
Created October 3, 2023 10:59
Run PHPCompatibility/PHPCompatibility on a directory using docker containers
FROM php:8.2-cli
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends git curl zip unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/cache/apk/* /usr/share/man /tmp/*
amnuts / workflow.yml
Created August 29, 2023 11:00
View inputs on a GitHub Action
default: "input value"
- name: "Show inputs"
run: echo "${{ toJSON(github.event.inputs) }}"
amnuts / phprc
Last active August 11, 2023 09:23
Dreamhost PHP 5.6 phprc file
date.timezone = "Europe/London"
expose_php = 0
extension =
extension =
extension =
suhosin.executor.include.whitelist = phar
amnuts / DateTimeInterval.php
Created December 14, 2021 09:37
Extend the \DateInterval class to have a __toString() method, returning the string representation of the object
use DateInterval;
class DateTimeInterval extends DateInterval
* Return the textual representation of an interval object
* @return string
import platform
import subprocess
def isMac() -> bool:
return platform.system() == 'Darwin'
def getMacProcessor() -> str:
return subprocess.check_output(['sysctl', '-n', 'machdep.cpu.brand_string']).decode('utf-8').rstrip()
amnuts /
Last active November 20, 2021 20:53
setting up WSL2

These are just some notes on my setting up of WSL

    I wanted to run WSL and the WSL docker containers from a location that wasn't my C drive, and this explains how
    Excluding WSL files from Windows Defender apparently helps to increase speed
    General commands to set things up that I wanted
amnuts / UnitTestCase.php
Created October 14, 2021 08:44
PHPUnit: mock an iterator
namespace Tests;
use ArrayIterator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class UnitTestCase extends TestCase
amnuts / phpstorm.bat
Last active June 22, 2021 17:04
Add context menu to Windows 7 to open file/folder in PhpStorm
@echo off
SET PhpStormPath=C:\Program Files (x86)\JetBrains\PhpStorm 8.0.2\bin\PhpStorm64.exe
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_SZ /v "" /d "Open in PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
echo Adding folder entries
amnuts / warm.php
Last active April 27, 2021 08:04
Fake pre-warm op-cache files for testing
$nums = range(0, 5000);
foreach ($nums as $i) {
$path = __DIR__."/files/c{$i}.php";
if (file_exists($path)) {
file_put_contents($path, "<?php\n\nfunction c{$i}() { return {$i}; }\n\n");