Skip to content

Instantly share code, notes, and snippets.

View amnuts's full-sized avatar

Andrew Collington amnuts

View GitHub Profile
amnuts / Dockerfile
Created October 3, 2023 10:59
Run PHPCompatibility/PHPCompatibility on a directory using docker containers
View Dockerfile
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
View workflow.yml
default: "input value"
- name: "Show inputs"
run: echo "${{ toJSON(github.event.inputs) }}"
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
View DateTimeInterval.php
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
View UnitTestCase.php
namespace Tests;
use ArrayIterator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class UnitTestCase extends TestCase
amnuts / warm.php
Last active April 27, 2021 08:04
Fake pre-warm op-cache files for testing
View warm.php
$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");
amnuts / propSearch.js
Created October 6, 2020 14:59
Helpers to see if object has all props or any of the props
View propSearch.js
const hasAllProps = function(list, within) {
list.forEach(function(e) {
if (!within.hasOwnProperty(e) || within[e] == "") {
return false;
return true;
const hasAnyProps = function(list, within) {
amnuts / directory-reflection.php
Created January 6, 2020 18:04
Using Better Reflection to get details on classes in multiple directories
View directory-reflection.php
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
require __DIR__ . '/vendor/autoload.php';
$refSubscriptions = [];
amnuts / datetime.php
Created June 4, 2019 15:57
PHP date/time conversion example
View datetime.php
foreach (range(1, 12) as $m) {
$elStart = new \DateTimeImmutable("2019-{$m}-10 23:50:00", new \DateTimeZone('Europe/London'));
$elEnd = $elStart->add(new \DateInterval('PT5H'));
$utcStart = $elStart->setTimezone(new \DateTimeZone('UTC'));
$utcEnd = $elEnd->setTimezone(new \DateTimeZone('UTC'));
printf("E/L: %s / %s, UTC: %s / %s\n",