Skip to content

Instantly share code, notes, and snippets.

View emmadesilva's full-sized avatar
🎩
HydePHP.com

Emma De Silva emmadesilva

🎩
HydePHP.com
View GitHub Profile
@emmadesilva
emmadesilva / build.yml
Created March 8, 2024 10:24
Basic Laravel Vite GitHub Actions CI Workflow
name: Build Laravel Vite assets for production
on:
push:
branches: [ "master" ]
permissions:
contents: write
@emmadesilva
emmadesilva / scaffold-posts-inverted.bash
Last active February 11, 2024 21:11
Scaffold a bunch of Markdown blog posts
#!/bin/bash
for i in {1..25}
do
# Calculate the date in reverse order
reversed_date="2024-01-01 12:$(printf "%02d" $((25 - i)))"
# Create the file with the specified content
echo "---" > "_posts/post-$i.md"
echo "title: 'Post $i'" >> "_posts/post-$i.md"
@emmadesilva
emmadesilva / rename-images-to-their-md5sums.sh
Created February 5, 2024 21:45
Renames images in the directory to their MD5 checksums
for file in *.jpg *.jpeg *.png *.gif *.webp; do
mv "$file" "$(md5sum "$file" | cut -d ' ' -f 1).${file##*.}"
done
# Interesting Blade in Markdown idea

How about something like this in Markdown?

<x-header image="media/my-image.png">
    <x-slot name="title">
        Lorem Ipsum
    </x-slot>
enum ImageSizes: string {
case Square = '768x768';
case Portrait = '512x768';
case Landscape = '768x512';
/** @return array{width: int, height: int} */
public function toArray(): array {
$size = explode('x', $this->value);
return [
@emmadesilva
emmadesilva / adminer.php
Created January 18, 2024 21:01
Adminer with SQLite support
<?php
// Super crude pasted together single file script to run Adminer with SQLite
class AdminerLoginSqlite {
function login($login, $password) {
return true;
}
@emmadesilva
emmadesilva / MakeUserCommand.php
Last active January 15, 2024 11:00
A simple Laravel `make:user` command
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class MakeUserCommand extends Command
{
protected $signature = 'make:user';
@emmadesilva
emmadesilva / laravel-pestphp-stability-test.php
Created January 12, 2024 11:14
Stability testing is such an amazing #PestPHP cheat.
<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('stability', function ($url) {
$this->get($url)->assertOk();
})->with(['/', '/about', '/terms-of-service']);
@emmadesilva
emmadesilva / the-breaking-change-checklist.md
Last active December 17, 2023 19:22
The Breaking Change Checklist

The Breaking Change Checklist

Introduction

So, I hear that you're thinking about introducing a breaking change. Well, let's see about that. First, pass the trials in this checklist, and then think about whether it's really a good idea.

The Checklist

  1. Does the change add any value?
@emmadesilva
emmadesilva / short-scale-to-human.php
Created November 9, 2023 16:21
Short-scale toHuman method
<?php
/**
* Format the number to a fluent human-readable string.
*
* @param int $number
* @param int $precision
* @return string
*/
public static function toHuman($number, $precision = 2)