Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / youtube_rss.txt
Last active May 29, 2025 21:55
YouTube RSS URLs
Channel: https://www.youtube.com/feeds/videos.xml?channel_id=<channel-id>
Playlist: https://www.youtube.com/feeds/videos.xml?playlist_id=<playlist-id>
User: https://www.youtube.com/feeds/videos.xml?user=<user_id>
Link: https://news.ycombinator.com/item?id=32192352
@ziadoz
ziadoz / ParallelTestingServiceProvider.php
Created May 23, 2025 15:28
Laravel 12 - Custom Connection for Parallel Testing
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Testing\Concerns\TestDatabases;
use Illuminate\Testing\ParallelTestingServiceProvider as LaravelParallelTestingServiceProvider;
// Laravel doesn't support changing the database connection when running tests in parallel, so we have to override the relevant method.
@ziadoz
ziadoz / firefox.sh
Created May 20, 2025 13:55
Isolate Firefox Profile
#!/usr/bin/env bash
PROFILEDIR="$(mktemp -d)"
firefox --no-remote --profile "$PROFILEDIR" --screenshot $PWD/output.png https://xkcd.com
rm -r "$PROFILEDIR"
@ziadoz
ziadoz / js-return.js
Created April 1, 2025 14:03
JS Function Return
// @see: https://github.com/hassanshaikley/pico-pubsub
foo = () => ('foo', 'bar');
console.log(foo()); // Returns 'bar'
@ziadoz
ziadoz / view-transitions.css
Created January 8, 2025 09:49
CSS View Transitions
@view-transition {
navigation: auto;
}
::view-transition-old(*),
::view-transition-new(*) {
animation: none;
mix-blend-mode: normal;
}
<?php
use ArrayAccess;
use Countable;
use IteratorAggregate;
use Traversable;
class Items implements ArrayAccess, Countable, IteratorAggregate
{
public function __construct(protected array $items = [])
{
@ziadoz
ziadoz / diff.php
Created December 13, 2024 14:36
Carbon - Diff in minutes/hours/days
<?php
> \Carbon\Carbon::now()->subMinutes(60)->longAbsoluteDiffForHumans();
= "1 hour"
> \Carbon\Carbon::now()->subMinutes(1440)->longAbsoluteDiffForHumans();
= "1 day"
> \Carbon\Carbon::now()->subMinutes(1560)->longAbsoluteDiffForHumans();
= "1 day"
@ziadoz
ziadoz / php84_lazy_proxy_object.php
Created November 30, 2024 18:33
PHP 8.4 - Lazy Proxy Objects
<?php
// @see: https://www.php.net/releases/8.4/en.php
// @see: https://www.php.net/manual/en/language.oop5.lazy-objects.php
// @see: https://www.youtube.com/watch?v=7J6Z0F4vItw
// A simple Foo class with a constructor, property and method...
class Foo
{
public string $foo;
@ziadoz
ziadoz / web.php
Last active February 5, 2025 22:50
Using Laravel 11's contextual attributes to populate a data object from POST data
<?php
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Container\ContextualAttribute;
use Illuminate\Support\Facades\Route;
/**
* Create a new contextual attribute that grabs fields from the request POST data.
*
* The equivalent of doing `$request->post($key, $default)` in a controller.
@ziadoz
ziadoz / tables.sql
Last active October 24, 2024 14:23
Table Timestamp Column Ordering - Put timestamps after id instead of at the end of the table
-- Typically it's common to add timestamp columns to the end of a database table, like this:
create table links (
id bigserial primary key,
link text,
created_at timestamp without time zone not null default now(),
updated_at timestamp without time zone not null default now(),
deleted_at timestamp without time zone null default null
);
-- However, when new columns are added it starts to look weird