Skip to content

Instantly share code, notes, and snippets.

View snellingio's full-sized avatar

Sam Snelling snellingio

View GitHub Profile
@snellingio
snellingio / macro.php
Created August 29, 2023 18:37
Filament highlight search
<?php
// AppServiceProvider boot
Str::macro('highlight', function ($string, $search, $highlight = '<mark class="highlight">$1</mark>', $caseSensitive = false, $minHighlightLength = 1) {
$toSearch = explode(' ', $search);
$searchable = [];
foreach ($toSearch as $key => $val) {
if (strlen($val) < $minHighlightLength) {
continue;
<?php
namespace App\Http\Livewire;
use App\Models\User;
use Livewire\Component;
use Livewire\WithPagination;
class SearchComponent extends Component
{
<?php
use Vector;
use PHPUnit\Framework\Assert;
expect()->extend('toBeWithin', function (float $expected, float $tolerance): void {
$actual = $this->value;
Assert::assertGreaterThanOrEqual($expected - $tolerance, $actual, "Expected {$actual} to be within {$tolerance} of {$expected}");
Assert::assertLessThanOrEqual($expected + $tolerance, $actual, "Expected {$actual} to be within {$tolerance} of {$expected}");
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
customElements.define('history-component', class extends HTMLElement {
connectedCallback() {
// get the history from localstorage, if it exists
// if the current route is the latest, do not add it to the history
// if the current route is not the latest, add it to the history
// if the history is longer than 5, remove the oldest
import { AssociativeArray } from '../php/types'
import array_key_exists from '../php/array_key_exists'
import is_callable from '../php/is_callable'
import is_string from '../php/is_string'
class Fluent {
private _attributes: AssociativeArray = {}
constructor(attributes: AssociativeArray = {}) {
Object.assign(this._attributes, attributes)
@snellingio
snellingio / component.html
Created January 17, 2022 18:20
Import Alpine components
<style>
[x-show="!open"] {
color: red;
}
[x-show="open"] {
color: green;
}
</style>
<template>
const plugin = require('tailwindcss/plugin')
module.exports = {
mode: 'jit',
purge: ['./resources/**/*.{js,vue,blade.php}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
<?php
namespace App\Http\Livewire\Sections;
use Livewire\Component;
use Livewire\TemporaryUploadedFile;
use Livewire\WithFileUploads;
class Photo extends Component
{
<div class="pb-6">
<label for="state" class="w-full block font-semibold pb-1 md:pb-2 select-none text-black dark-mode:text-grey-050">
State
</label>
<div class="w-full block flex">
<div class="relative w-full">
<select class="border border-grey-100 bg-white outline-none px-3 rounded appearance-none outline-none w-full py-3 bg-white text-black focus:border-blue-500" id="state" name="state">
@snellingio
snellingio / keybase.md
Created November 28, 2016 13:11
keybase.md

Keybase proof

I hereby claim:

  • I am snellingio on github.
  • I am snelling (https://keybase.io/snelling) on keybase.
  • I have a public key whose fingerprint is 38E0 0D78 326C F14B C7A1 BA06 3696 BFC7 1915 95E4

To claim this, I am signing this object: