Skip to content

Instantly share code, notes, and snippets.

View trovster's full-sized avatar

Trevor Morris trovster

View GitHub Profile
@trovster
trovster / code-style.yml
Created February 7, 2025 14:10
My GrumPHP and Workflow tasks for code style.
name: Code Style & Static Analysis
on:
push:
branches:
- develop
- feature/*
workflow_dispatch:
jobs:
@trovster
trovster / BlogController.php
Created February 5, 2025 09:14
API Controllers and Resources for Laravel
<?php
namespace App\Http\Controllers\Subdomains\Api;
use App\Http\Controllers\Subdomains\Api\Controller;
use App\Http\Requests\Api\Blog\StoreRequest;
use App\Http\Requests\Api\Blog\UpdateRequest;
use App\Http\Resources\Blog\Post as Resource;
use App\Http\Resources\Blog\Posts as Collection;
use App\Models\Blog\Post;
@trovster
trovster / rector.php
Last active January 22, 2025 13:57
My current Rector configuration
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
@trovster
trovster / cli.md
Last active October 1, 2024 08:10
Re-installing MariaDB/MySQL on macOSX

Install Brew Packages

$ brew install git dnsmasq mariadb nginx redis
$ brew install node npm nvm
$ brew install bat zsh zsh-syntax-highlighting

Log in to MySQL

@trovster
trovster / eleventy.config.js
Created August 22, 2024 17:29
Simplify adding filters in Eleventy
for (const [name, filter] of Object.entries(filters)) {
if (['getDescription', 'getRSSlink'].includes(name)) {
eleventyConfig.addAsyncFilter(name, filter)
} else {
eleventyConfig.addFilter(name, filter)
}
}
@trovster
trovster / Content.php
Created February 20, 2023 11:07
Content model for markdown
<?php
namespace App\Models;
use App\Models\Base as Model;
use App\Support\Str;
use App\Support\Stringable;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;
use Spatie\YamlFrontMatter\YamlFrontMatter;
@trovster
trovster / ErrorChecking.php
Last active January 27, 2023 13:57
Check links for HTTP errors and optionally mark them as broken. `php artisan link:error-checking {--update}`
<?php
namespace App\Console\Commands\Link;
use App\Models\Link\Link;
use App\Support\Str;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Client\ConnectionException;
@trovster
trovster / PostSpecificReplay.php
Last active December 7, 2022 11:52
Replaying POST requests using Laravel Middleware + Service
<?php
namespace App\Http\Middleware;
use App\Services\ReplayRequest;
use Closure;
use Illuminate\Http\Request;
class PostSpecificReplay
{
@trovster
trovster / TM.js
Created June 11, 2022 20:54
Using shrhdk/text-to-svg to convert "TM" to SVG paths, using font and multiple colours.
const TextToSVG = require('text-to-svg')
const textToSVG = TextToSVG.loadSync('fonts/Inter.woff')
const colours = Object.values({
blue: '#2490BA',
pink: '#d60058',
purple: '#5f01ad',
green: '#048242',
orange: '#e87204'
}).reverse()
@trovster
trovster / Property.php
Created June 9, 2022 07:48
Get properties, ordered by the distance from an existing property. Latitude and longitude are stored in the address relationship.
<?php
// Property::query()->nearest($property)->limit(5)->get();
// $property->nearest()->limit(5)->get();
public function scopeNearest(Builder $query, ?Property $property = null): Builder
{
$property = $property ?? $this;
$earthRadius = 3959;
$latitude = $property->address->lat;