Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / extension_versions.php
Created October 16, 2025 16:16
PHP Extension Versions
<?php
foreach (get_loaded_extensions() as $extension) {
echo "$extension: " . phpversion($extension) . "\n";
}
@ziadoz
ziadoz / DownloadController.php
Last active October 16, 2025 11:07
Laravel 12.x - Download Zip of Multiple Files
<?php
class DownloadController extends Controller
{
public function download(Request $request): StreamedResponse
{
$filename = 'unique-filename.zip';
$checksum = base64_encode(hash('xxh128', $filename, true));
if (in_array($checksum, $request->getETags())) {
@ziadoz
ziadoz / env-object.php
Last active October 22, 2025 09:10
PHP Read Only Env Var Object
<?php
declare(strict_types=1);
// A PHP library like Pydantic settings where a config object maps automatically to env vars.
// The object should be read-only. Super simple in scope.
// Attributes: Env\String(), Int, Float, Bool, ArrayList, ArrayMap, Laravel Collection OptionsMap (list of allowed values) DSN, JSONMap, JSONArray, Nullable* Enums, Constants (e.g. PDO_* etc.). Default parameter. Prefixed, Fallback. Callable(fn () => ...)
// Ability to read from $_ENV or getenv(). Need two "Reader" classes. Reader could handle PREFIX_ stuff more naturally.
// EnvReader::set(new ServerEnvReader()), EnvReader::get()
// new GetEnvReader(), new PrefixedEnvReader(new GetEnvReader()), new FallbackEnvReader(..., ...)
// new DotEnvReader(), loads using dot env package, then reads from vars rather than set in $_ENV.
@ziadoz
ziadoz / download-unicode-db.php
Created September 20, 2025 15:48
Download Unicode Database
<?php
// Download Unicode database CSV:
$ch = curl_init();
curl_setopt_array($ch, $options = [
CURLOPT_URL => 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_FAILONERROR => true,
@ziadoz
ziadoz / LoggingOutput.php
Last active September 10, 2025 11:40
Laravel 12.x - Use Custom Artisan Output
<?php
// A rubbish AI-generated logger output class:
namespace App\Console\Output;
use Illuminate\Support\Facades\Log;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\Output;
@ziadoz
ziadoz / debug_playwright.sh
Created September 4, 2025 12:49
Debug Playwright Command
#!/usr/bin/env bash
DEBUG=pw:protocol DEBUG_FILE=logs.txt ./node_modules/.bin/playwright run-server --host [HOST] --port [PORT] --mode launchServer
@ziadoz
ziadoz / console.php
Created September 2, 2025 15:31
Laravel 12 - What happens when queue:work command is killed...
<?php
// In a Terminal tab run:
// > php artisan scratch && php artisan queue:work --queue=test
//
// In a new Terminal tab run:
// > kill -[NUM] $(pidof -s php artisan queue:work)
//
// Results:
// -2 (SIGINT) = Job continues looping.
@ziadoz
ziadoz / docker-compose.yml
Created July 29, 2025 15:44
Connect CyberDuck client to Docker Minio Instance
services:
minio:
image: minio/minio:latest
restart: always
hostname: minio
ports:
- "9000:9000"
- "9001:9002"
environment:
MINIO_ROOT_USER: minio
@ziadoz
ziadoz / easy_dual_boot_win_lin.txt
Created July 3, 2025 22:23
Easy Dual Boot Windows/Linux
A simple way to dual boot that doesn't involve messing around with boot managers and master boot records:
- Install Windows on SSD 1.
- Disconnect SSD 1.
- Install Linux on SSD 2.
- Reconnect SSD 1.
- Use BIOS boot device selector menu to switch (e.g. F8).
@ziadoz
ziadoz / console.php
Last active June 5, 2025 09:13
Laravel 12.x - Lazy Ghost Contextual Attribute
<?php
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Container\ContextualAttribute;
use Illuminate\Support\Facades\Artisan;
#[Attribute(Attribute::TARGET_PARAMETER)]
class LazyGhost implements ContextualAttribute
{
/**