Skip to content

Instantly share code, notes, and snippets.

View olivM's full-sized avatar

Olivier Mourlevat olivM

View GitHub Profile
@props([
'src',
'title' => null,
'alt' => null,
])
@php
preg_match('/.*\/embed\/([^?&\/]+)/m', $src, $matches);
$id = $matches[1];
$alt ??= $title ?? 'Embedded YouTube video';

Role

You are a senior Laravel engineer (Laravel 12+), expert in PHP, Livewire 3, Pest PHP, and Tailwind CSS.
You maintain a podcast-management platform used by hosts and producers to run their shows and interact with listeners.

Task

Create a planning document for the feature described below.
Do not write code.

Output file

  • Location : project root

Style

  • Don't use too many comments unless there is something non-obvious going on.
  • In general, use DTOs over arrays of data when consuming data from APIs. Saloon has first-party support for casting responses to DTOs, if you need help understanding it, check their documentation.
  • When implementing DTOs, use the simplest approach that works - plain PHP objects are often sufficient.
  • Follow existing code formatting and naming conventions in the project.
  • Check if the project has a code formatter/linter and use it before submitting changes.

Acceptance criteria

  • If you are building a new feature or refactoring, be absolutely certain to run the tests before telling me you are done.
  • When the tests relating to your feature are passing, make sure to also run the entire test suite to ensure you didn't break other tests.
# SETUP #
DOMAIN=example.com
PROJECT_REPO="[email protected]:example.com/app.git"
AMOUNT_KEEP_RELEASES=5
RELEASE_NAME=$(date +%s--%Y_%m_%d--%H_%M_%S)
RELEASES_DIRECTORY=~/$DOMAIN/releases
DEPLOYMENT_DIRECTORY=$RELEASES_DIRECTORY/$RELEASE_NAME
# stop script on error signal (-e) and undefined variables (-u)
<?php
namespace App\Helper;
trait WpTrait
{
/**
* Replaces double line-breaks with paragraph elements.
@kiding
kiding / NoScrollOnInputFocusiOSSafari.html
Last active September 24, 2025 00:52
Preventing iOS Safari scrolling when focusing on input elements
<!--
When an input element gets focused, iOS Safari tries to put it in the center by scrolling (and zooming.)
Zooming can be easily disabled using a meta tag, but the scrolling hasn't been quite easy.
The main quirk (I think) is that iOS Safari changes viewport when scrolling; i.e., toolbars shrink.
Since the viewport _should_ change, it thinks the input _will_ move, so it _should_ scroll, always.
Even times when it doesn't need to scroll—the input is fixed, all we need is the keyboard—
the window always scrolls _up and down_ resulting in some janky animation.
However, iOS Safari doesn't scroll when the input **has opacity of 0 or is completely clipped.**
@byevhen2
byevhen2 / apiRequest.js
Last active October 7, 2025 22:04 — forked from phpbits/apiRequest.js
Using wp.apiRequest to access custom endpoints.
// See: wp-includes/js/api-request.js
// Returns a jqXHR object. See: https://api.jquery.com/jQuery.ajax/#jqXHR
wp.apiRequest({path: '/namespace/vendor/v1/config'})
.then(configOptions => console.log(configOptions));
// jqXHR object has method then(), but does not have methods catch() or
// finally(). Use fail() or always() instead
wp.apiRequest({path: '/namespace/vendor/v1/config'})
.done(configOptions => console.log(configOptions))
@AshishDhamalaAD
AshishDhamalaAD / Merge specific files from one branch to another.md
Last active December 3, 2020 17:07
How to pick specific files from one branch and add it to another branch

Let's say there are two branches: master and feature-one.

There are some files that you want in the master branch from the feature-one branch but not all the files. Let's say those files are:

app/Models/User.php
app/Controllers/UsersController.php

You can accomplish that by doing the following:

@matt-allan
matt-allan / README.md
Created July 31, 2020 20:49
Compound sorting Laravel collections

This is an example of sorting a Laravel collection by > 1 attribute with different sort directions. Unlike some of the other solutions mentioned in this thread it works with any type PHP can normally sort and doesn't require hashing.

That works because of how PHP's comparison functions work:

Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value

The <=> operator is PHP's combined comparison operator, or 'spaceship' operator. It makes writing custom sort functions very easy.

If you need to do a compound sort but every attribute is being sorted in the same direction, you can use sortBy/sortByDesc instead of writing your own sort function.

@miken32
miken32 / Cidr.php
Last active November 27, 2025 13:47
Laravel CIDR validation rule
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use const FILTER_FLAG_IPV4;
use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_INT;