Skip to content

Instantly share code, notes, and snippets.

View trovster's full-sized avatar

Trevor Morris trovster

View GitHub Profile
@trovster
trovster / gist:2252907
Created March 30, 2012 16:57
A PHP function to output start and end dates, allowing for for short syntax March 3rd-10th 2012 (if in same month & year).
<?php
/**
* event_output_start_end_date
* @param string $start_date
* @param string $end_date
* @return string
*/
function event_output_start_end_date($start_date, $end_date) {
$start_datetime = strtotime($start_date); // yyyy-mm-dd
$end_datetime = strtotime($end_date); // yyyy-mm-dd
@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 / example.html
Created April 29, 2020 09:28
Using Tailwind with BEM
<button class="button">
Standard Button
</button>
<button class="button button--red">
Red Button
</button>
<button class="button button--inline">
Inline Button
@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;
@trovster
trovster / commands.txt
Created April 6, 2022 09:19
Setting up Ubuntu for consistent DX
sudo apt install zsh bat
zsh --version
chsh -s $(which zsh)
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# General
alias zshconfig="vi ~/.zshrc"
alias ls="ls -la -h -Gp -F --color=auto"
alias grep="grep -n --color"
@trovster
trovster / development.sh
Last active December 26, 2021 14:33
Starting point for a script to setup development environment (MAMP)
#!/bin/sh
# chmod a+x development.sh
# General functionality
brew install git
brew install openssl
brew install node
brew install npm
brew install yarn
brew install bat
@trovster
trovster / Money.php
Last active October 11, 2021 14:06
Money View component
<?php
namespace App\View\Components\Form;
use App\View\Components\Base as Component;
use Illuminate\Contracts\View\View as Response;
use Money\Money as MoneyObject;
use NumberFormatter;
class Money extends Component