Skip to content

Instantly share code, notes, and snippets.

View liamja's full-sized avatar
💾

Liam Anderson liamja

💾
View GitHub Profile
@liamja
liamja / alpine-query.js
Last active April 10, 2024 18:24
An Alpine.js plugin to store state in the query string
Alpine.plugin((Alpine) => {
Alpine.magic('query', () => (params) => {
const url = new URL(window.location.href)
// For each key in the params object, set the value to the query string value or the default value
let reactiveParams = Alpine.reactive(Object.keys(params).reduce((newParams, key) => {
const defaultValue = params[key]
const value = url.searchParams.get(key)
newParams[key] = value ?? defaultValue
@liamja
liamja / Sparkline.php
Created August 22, 2023 17:54
Generate sparklines with vanilla PHP
<?php
class Sparkline
{
public $values = [];
public $width = '4em';
public $height = '1em';
@liamja
liamja / AppServiceProvider.php
Created August 16, 2023 16:30
UUID Livewire Synthesizer
// Add to AppServiceProvider::boot()
Livewire::propertySynthesizer(\App\Livewire\Synths\UuidSynth::class);
@liamja
liamja / AppServiceProvider.php
Last active March 22, 2024 09:06
Laravel Helpers
<?php // Pop these in App\Providers\AppServiceProvider::boot()
// Exception Handling
Blade::directive('try', fn ($x) => '<?php try { ?>');
Blade::directive('catch', fn ($x) => "<?php } catch ($x) { ?>");
Blade::directive('finally', fn ($x) => '<?php } finally { ?>');
Blade::directive('endtry', fn ($x) => '<?php } ?>');
// JSON Encode
Blade::directive('json', fn ($x) => "<?php echo \Illuminate\Support\Js::encode($x); ?>");
@liamja
liamja / Postcode.php
Created July 25, 2023 14:18
UK Postcode Validation Rule for Laravel
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
/**
* UK Postcode Validation Rule.
*
@liamja
liamja / laravel-worker.service
Created October 21, 2019 15:28
Laravel Worker as a systemd Service Unit
[Unit]
Description=Laravel Worker
Wants=network-online.target
[Service]
Type=simple
User=forge
ExecStart=/usr/bin/php /var/www/artisan queue:work
Restart=always
RestartSec=5
@liamja
liamja / keybase.md
Created April 12, 2014 04:14
Keybase.io Verification

Keybase proof

I hereby claim:

  • I am liamja on github.
  • I am liamja (https://keybase.io/liamja) on keybase.
  • I have a public key whose fingerprint is 7F6D 981C 6635 9A15 1CC5 1866 889E CB40 163C B640

To claim this, I am signing this object:

@liamja
liamja / vst~
Last active August 29, 2015 13:57
vst~
----------begin_max5_patcher----------
398.3ocsS9rTBCCDF+b6SQl30JCArHpG4hWjW.GGmP6ZILoI0ljJJC9ra9Sq
TTFGGAOzzte6lMe8WR1DGgWHWCJL5Zz8nnnMwQQdImPTabDtjtNiSU9xvkfR
QK.bRHmFVq85xJPzIJLkRilCZ+THspOIEZE6MvqMZvvV4JpNaIST7XMjoCNg
jNzl19xMN9J+21QzCsSIzb8qUPndL9yTtEQPK8Iv2B7FPyxnn4fAP2A4LSYm
IY4AeuX04S6Yblny2ibZaiicCIGIcp3lBzLqu3ypMpkP8oCU6HEgb4+NpROY
nR.uXa32HUiR+9ggyz+HblDNLQFOHMAMh7SvQwJDTNNo+WtGNSocuYBcmj+4
3XI4vrrUTQa5r0YycqVfLVyHo4FA6YCX6UBx9uguw5jdaAdaYMs3qWs8Lxou
+9hRZpy5Vr1KDncXJGTZlfpYRQuZH6UyRVdN3S2sejyTzEbv+6N7fmO9stI8
ezMATQqpZfZUaK8FwdXckr1ENIwGxDgPeGw0PCqq9Khccaa7Gv5QBQK
<?php
?>Ho! Ho! Ho!<?php
?>
@liamja
liamja / logKextManager.m
Last active December 24, 2015 21:38 — forked from anonymous/OSReturnAsString.c
Log the return value of the Kext Manager in a human-readable form.
- (void)logKextManager:(OSReturn)osr
{
switch (osr) {
case kOSMetaClassDuplicateClass:
NSLog(@"A duplicate Libkern C++ classname was encountered during kext loading.");
break;
case kOSMetaClassHasInstances:
NSLog(@"A kext cannot be unloaded because there are instances derived from Libkern C++ classes that it defines.");
break;
case kOSMetaClassInstNoSuper: