Skip to content

Instantly share code, notes, and snippets.

View nullthoughts's full-sized avatar

Jani Gyllenberg nullthoughts

View GitHub Profile
@nullthoughts
nullthoughts / ttfb.zsh
Last active September 29, 2026 16:47
A small zsh function that checks time to first byte (TTFB) on one host across multiple paths. Pass the host and the relative URLs, and it prints the status code, TTFB, and total time for each. The output is plain text, so you can paste it straight into an issue, a Slack thread, or Claude.
# ttfb — quick TTFB checks for multiple paths on one host. Paste-ready output.
#
# Install: add to ~/.zshrc (or source this file), then run: source ~/.zshrc
# Usage: ttfb example.com /up /products /about
# Auth: TTFB_AUTH='user:pass' ttfb example.com /
#
# Defaults to https:// and tests / when no paths are given.
# Colors: status (2xx green, 3xx yellow, 4xx/5xx red), TTFB (<300ms green, <800ms yellow, slower red)
ttfb() {
@nullthoughts
nullthoughts / MacroServiceProvider.php
Last active February 22, 2025 19:29
Convert Laravel Scout query to Eloquent query (Macro)
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Laravel\Scout\Builder;
class MacroServiceProvider extends ServiceProvider
{
/**
@nullthoughts
nullthoughts / DuskServiceProvider.php
Last active February 4, 2023 21:45
Mock classes & routes in Laravel Dusk tests
<?php
namespace App\Providers;
class DuskServiceProvider extends ServiceProvider
{
/**
* The classes that should be mocked for Dusk tests
*
* @var array
@nullthoughts
nullthoughts / PipelineFilter.php
Created September 8, 2021 20:20
Pipeline extended with second parameter (with data)
<?php
namespace App\Filters;
use Closure;
use Illuminate\Pipeline\Pipeline;
use Throwable;
class PipelineFilter extends Pipeline
{
@nullthoughts
nullthoughts / scopeBySaleType.php
Created October 23, 2019 14:04
scopeBySaleType
public function scopeBySaleType($query, type)
{
$query->whereHas('sales', function ($query) use ($type) {
$query->where('id', function ($sub) {
$sub->from('sales')
->selectRaw('max(id)')
->whereColumn('sales.inventory_id', 'inventories.id');
})->where('type', $type);
});
}
@nullthoughts
nullthoughts / helpers.php
Created September 7, 2019 21:50
Lode app console() method helper for Laravel
if(! class_exists(\LodeApp\PHPUnit\Console::class)) {
function console($vars, $dump = true) {
dump($vars);
}
}
@nullthoughts
nullthoughts / LockColumns.php
Created May 2, 2019 16:35
Lock columns/attributes from updates in Laravel
<?php
namespace App\Traits;
trait LockColumns
{
/**
* Cast locked_columns as a JSON column
*
* @return void
@nullthoughts
nullthoughts / CorsHeaders.php
Created March 7, 2019 20:32
Laravel CORS Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class CorsHeaders
{
/**
* Handle an incoming request.
@nullthoughts
nullthoughts / AdvancedAlgoliaEngine.php
Created January 16, 2019 17:48
Custom Algolia Engine for Laravel to only index updated models
<?php
namespace App\Engines;
use Illuminate\Support\Collection;
use Laravel\Scout\Engines\AlgoliaEngine;
class AdvancedAlgoliaEngine extends AlgoliaEngine
{
@nullthoughts
nullthoughts / batchRename.php
Created September 19, 2018 21:42
Batch rename/move files with callback function
public static function testRename()
{
self::batchRename('s3', 'documents', function ($file) {
return str_replace('%20', '-', $file);
});
}
public static function batchRename($disk, $directory, $callback)
{
$disk = \Illuminate\Support\Facades\Storage::disk($disk);