Skip to content

Instantly share code, notes, and snippets.

View devhammed's full-sized avatar
💭
Changing the world, one dollar sign in my PHP code at a time!

Hammed Oyedele devhammed

💭
Changing the world, one dollar sign in my PHP code at a time!
View GitHub Profile
@devhammed
devhammed / CssSelectorRule.php
Created July 8, 2026 20:23
Laravel CSS Selector Validation Rule
<?php
declare(strict_types=1);
namespace App\Rules;
use Closure;
use DOMException;
use Dom\HTMLDocument;
use Illuminate\Contracts\Validation\ValidationRule;
@devhammed
devhammed / use-pluck.ts
Created July 6, 2026 16:58
Helper hook to extract key or key-value pairs from an array of objects.
import { useMemo } from 'react';
export type UsePluckKeys<T, K extends keyof T> = T[K][];
export type UsePluckKeyValues<T, K extends keyof T, V extends keyof T> = Record<T[K] & PropertyKey, T[V]>;
export type UsePluck<T, K extends keyof T, V extends keyof T> = UsePluckKeys<T, K> | UsePluckKeyValues<T, K, V>;
export function usePluck<T, K extends keyof T>(options: T[], key: K): UsePluckKeys<T, K>;
@devhammed
devhammed / NotifyOfNewLike.php
Last active May 26, 2026 21:54
Laravel Aggregated Notification Implementation (https://x.com/akinkunmi/status/2058950199163207690?s=20)
<?php
namespace App\Jobs;
use App\Models\Post;
use App\Models\Like;
use App\Models\User;
use App\Notifications\AggregatedLikeNotification;
use App\Notifications\SingleLikeNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
@devhammed
devhammed / alpine-floating-placeholder.js
Created May 21, 2026 18:49
Alpine.js Floating Input Placeholder
window.Alpine.directive('placeholder', (el, context, framework) => {
if (el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA') {
throw new Error('The `x-placeholder` directive can only be used on an `input` or `textarea` element.');
}
const placeholder = el.getAttribute('placeholder');
if (!placeholder) {
return;
}
@devhammed
devhammed / Caddyfile
Last active August 14, 2026 23:28
Laravel Docker Setup (Caddy, Frankenphp, Queue Worker, Octane, Scheduler, Reverb)
{
{$CADDY_GLOBAL_OPTIONS}
admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT}
log {
level {$CADDY_SERVER_LOG_LEVEL:INFO}
output {$CADDY_SERVER_LOG_OUTPUT:stdout}
# Redact the authorization parameters...
format filter {
@devhammed
devhammed / async-v2.php
Created April 4, 2026 18:50
Async PHP v2 (This is another attempt at Async PHP using stream socket pair capabilities.
<?php
declare(strict_types=1);
function async(Closure $task): Closure
{
static $resolved = [];
static $id = 0;
@devhammed
devhammed / use-animation-frame.ts
Created March 3, 2026 17:51
React Use Animation Frame Hook
import { DependencyList, useCallback, useEffect, useRef } from 'react';
const raf =
typeof window !== 'undefined'
? window.requestAnimationFrame ||
((cb: FrameRequestCallback) => window.setTimeout(() => cb(Date.now()), 1_000 / 60))
: () => undefined;
const caf = typeof window !== 'undefined' ? window.cancelAnimationFrame || window.clearTimeout : () => undefined;
@devhammed
devhammed / bundle_monorepo_packages.ts
Last active March 2, 2026 18:46
Adonis.js "buildFinished" hook that copies monorepo packages into the build folder.
import { hooks } from '@adonisjs/core/app'
import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
import path from 'node:path'
const PACKAGE_PREFIX = 'flowshub-'
export default hooks.buildFinished(async (bundler) => {
const repoRoot = path.resolve(bundler.cwdPath, '../../')
const buildDir = path.join(bundler.cwdPath, 'build')
@devhammed
devhammed / transmit.ts
Last active February 26, 2026 10:33
AdonisJS v7 Transmit Setup (you must uninstall the official package then register the custom provider and preload file).
import type { HttpContext } from '@adonisjs/core/http'
import app from '@adonisjs/core/services/app'
import router from '@adonisjs/core/services/router'
import { RuntimeException } from '@poppinss/utils/exception'
const transmit = await app.container.make('transmit')
transmit.authorize<{ id: string }>('users/:id', async (ctx: HttpContext, params) => {
const userId = ctx.auth.user?.id
@devhammed
devhammed / FormatsResponse.php
Created February 25, 2026 07:24
Laravel Response Formatter
<?php
declare(strict_types=1);
namespace App\Concerns;
use Closure;
use Inertia\Inertia;
use Inertia\Response;
use InertiaUI\Modal\Modal;