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 / yiq.php
Last active February 1, 2025 06:47
Calculating Color Contrast using YIQ
function getContrastYIQ(string $hexColor): string
{
$hex = str_replace('#', '', $hexColor);
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
@devhammed
devhammed / parse_http_request.php
Last active January 31, 2025 17:19
Parse HTTP Request in PHP
<?php
function parse_http_request(string $request): array
{
[$rawHeaders, $rawBody] = mb_split('\r\n\r\n', $request, 2);
$rawHeaders = mb_split('\r\n', $rawHeaders);
$requestLine = array_shift($rawHeaders);
<?php
namespace App\Listeners;
use Exception;
use Throwable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Process;
@devhammed
devhammed / Connection.php
Last active November 17, 2024 22:06
Multiple OAuth Connections Support using Laravel Socialite (https://laravel.com/docs/socialite)
<?php
namespace App\Models;
use App\Enums\ConnectionProviderType;
use Illuminate\Database\Eloquent\Model;
use Database\Factories\ConnectionFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@devhammed
devhammed / CurrencySynthesizer.php
Created October 26, 2024 08:58
Livewire Synthesizer for Money and Currency objects from https://github.com/akaunting/laravel-money package.
<?php
namespace App\Support\Synthesizers;
use Akaunting\Money\Currency;
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
class CurrencySynthesizer extends Synth
{
public static string $key = 'currency';
@devhammed
devhammed / laravel-github-actions-deploy.yml
Created October 26, 2024 08:10
Laravel GitHub Actions Deployment Workflow (Filament, Scheduler, Queue, Reverb, Pulse, NPM)
name: Deploy to Servers
on:
push:
branches:
- production
jobs:
production-deploy:
runs-on: ubuntu-latest
@devhammed
devhammed / LaravelHelpers.php
Created October 25, 2024 13:14
My favourite Laravel helper functions
<?php
if ( ! function_exists('vite')) {
/**
* Get the Vite instance or Vite asset URL for the given file.
*/
function vite(?string $file = null, ?string $buildDirectory = null): Illuminate\Foundation\Vite|string
{
$vite = app(Illuminate\Foundation\Vite::class);
@devhammed
devhammed / PinInput.php
Created October 25, 2024 13:09
Filament PIN Input
<?php
namespace App\Frontend\Forms\Components;
use Closure;
use Filament\Forms\Components\Field;
class PinInput extends Field
{
protected Closure|int|null $length = null;
@devhammed
devhammed / MoneyInput.php
Last active January 22, 2025 10:36
Filament Money Input Component (this assumes that you are using the MoneyCast from https://github.com/akaunting/laravel-money package for the field in your model, this package is depended on by default in FilamentPHP so this should work out of the box))
<?php
namespace App\Frontend\Forms\Components;
use Closure;
use Akaunting\Money\Money;
use Filament\Support\RawJs;
use Akaunting\Money\Currency;
use Filament\Forms\Components\TextInput;
@devhammed
devhammed / .gitlab-ci.yml
Last active February 1, 2024 17:35
GitLab Deploys Pipeline for Laravel (with environments and rollback support)
stages:
- deploy
production-deploy:
stage: deploy
environment: production
only:
- /^v.*$/
script:
- which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)