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 / combobox.tsx
Last active December 11, 2025 09:23
ShadCN UI Combobox (based on Command and Popover components).
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command';
import { CheckIcon, SearchIcon, UnfoldMoreIcon } from '@/components/ui/icons';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { useControlledState } from '@/hooks/use-controlled-state';
import { cn } from '@/lib/utils';
import { Command as CommandPrimitive } from 'cmdk';
import * as React from 'react';
import ReactDOM from 'react-dom';
type ComboboxContextValue = {
@devhammed
devhammed / ContentNegotiator.php
Created December 4, 2025 09:33
Laravel Content Negotiator Middleware (e.g. /glossaries for HTML & /glossaries.json for JSON)
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ContentNegotiator
{
@devhammed
devhammed / use-controlled-state.ts
Last active December 11, 2025 08:45
Use Controlled State hook manages a value that can be either controlled or uncontrolled. It returns the current state and a setter that updates internal state when uncontrolled and always calls an optional onChange callback.
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
import { flushSync } from 'react-dom';
export function useControlledState<T>(
initialValue: T,
controlledValue?: T,
onChange?: (value: T) => void,
): [T, (value: T | ((prev: T) => T)) => void] {
const [internalValue, setInternalValue] = useState(initialValue);
@devhammed
devhammed / data-table.tsx
Last active December 11, 2025 08:45
ShadCN UI Data Table with pagination (server, client, infinite), row selection, column visibility, column filtering (server, client), column sorting (server, client).
import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from '@/components/ui/table';
import { useControlledState } from '@/hooks/use-controlled-state';
import { cn } from '@/lib/utils';
import { InfiniteScroll } from '@inertiajs/react';
import {
ColumnDef,
ColumnFiltersState,
flexRender,
getCoreRowModel,
getFilteredRowModel,
@devhammed
devhammed / parse-separated.ts
Created November 13, 2025 13:57
Parse separated string (CSV, TSV, SSV) according to [RFC-4180](https://www.ietf.org/rfc/rfc4180.txt).
function parseSeparated(text: string, delimiter: string = ','): string[][] {
const rows: string[][] = [];
let field = '';
let row: string[] = [];
let inQuotes = false;
for (let i = 0; i < text.length; i++) {
const char = text[i];
const next = text[i + 1];
@devhammed
devhammed / use-object-url.ts
Last active November 10, 2025 19:59
React Hook For Managing Object URLs.
import { useEffect, useState } from 'react';
export type BlobType = File | Blob | MediaSource | null;
export function useObjectUrl(initialObject: BlobType | (() => BlobType) = null) {
const [objectUrl, setObjectUrl] = useState<string | null>(null);
const [object, setObject] = useState<BlobType>(initialObject);
useEffect(() => {
@devhammed
devhammed / BackgroundPollingJob.php
Created November 7, 2025 00:43
Laravel Background Polling Queue Job is a job that checks for the status of something in any source like external API or database and re-queue itself if the item is not at the desirable status yet.
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class BackgroundPollingJob implements ShouldQueue
@devhammed
devhammed / tap.ts
Created October 31, 2025 14:07
Implementation Of Laravel "tap" Helper In TypeScript
type TapProxy<T extends object> = {
[K in keyof T]: T[K] extends (...args: infer A) => unknown
? (...args: A) => T
: T[K];
};
function tap<T extends object>(obj: T): TapProxy<T>;
function tap<T extends object>(obj: T, fn: (target: T) => void): T;
function tap<T extends object>(
obj: T,
@devhammed
devhammed / Laravel.Dockerfile
Last active November 14, 2025 12:40
Laravel Docker Setup (NGINX, PHP-FPM, Queue Worker, Scheduler, Reverb)
# Stage 1: Build
FROM php:8.4-cli AS build
# Setup build root
WORKDIR /app
# Install dependencies
RUN apt-get update && apt-get install -y \
git \
unzip \
@devhammed
devhammed / scroll-area.tsx
Last active December 14, 2025 18:48
Shadcn UI Scroll Area with Overflow Fading Support
import { cn } from '@/lib/utils';
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
import * as React from 'react';
import { useEffect, useRef, useState } from 'react';
const ScrollArea = React.forwardRef<
React.ComponentRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> & {
orientation?: 'horizontal' | 'vertical';
fade?: boolean;