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 / 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
Created October 10, 2025 17:50
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> & { fade?: boolean }
>(({ className, fade, children, ...props }, ref) => {
const viewPortRef = useRef<HTMLDivElement | null>(null);
@devhammed
devhammed / use-api-form.ts
Last active November 14, 2025 06:01
Laravel Inertia JSON API Form Helper Hook
import { FormDataKeys, FormDataType, Method } from '@inertiajs/core';
// @ts-expect-error TS2307
import type { Response } from '@inertiajs/core/types/response';
import type { InertiaFormProps } from '@inertiajs/react';
import { useForm } from '@inertiajs/react';
import axios, { AxiosProgressEvent, AxiosRequestConfig, AxiosResponse } from 'axios';
import { cloneDeep } from 'lodash-es';
import { useCallback, useMemo, useRef, useState } from 'react';
type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
@devhammed
devhammed / MoneyCast.php
Last active October 10, 2025 07:49
Brick Money Cast for Laravel Eloquent Models (handles storing to database, getting from database & JSON serialization)
<?php
namespace App\Casts;
use Brick\Money\Money;
use UnexpectedValueException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Contracts\Database\Eloquent\SerializesCastableAttributes;
@devhammed
devhammed / input-tags.tsx
Last active October 10, 2025 17:52
Shadcn UI Tags Input
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { XIcon } from '@/components/ui/icons';
import { cn } from '@/lib/utils';
import {
type ChangeEvent,
type ComponentProps,
type KeyboardEvent,
forwardRef,
useCallback,
@devhammed
devhammed / 01-audit.module.ts
Last active September 12, 2025 09:42
Nest.js Audit Module (request with all database operations that happened in the request-response flow)
import {
forwardRef,
MiddlewareConsumer,
Module,
NestModule,
} from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Audit } from '@/audit/entities/audit.entity';
import { AuditMiddleware } from '@/audit/middlewares/audit.middleware';
import { APP_GUARD } from '@nestjs/core';