Skip to content

Instantly share code, notes, and snippets.

View DerekBuntin's full-sized avatar

Derek Buntin DerekBuntin

View GitHub Profile
@tuto1902
tuto1902 / chatbox.blade.php
Last active August 16, 2024 21:50
Livewire Chat Box Component
<?php
use App\Events\MessageSent;
use Livewire\Volt\Component;
new class extends Component
{
/**
* @var string[]
*/
@MrPunyapal
MrPunyapal / database-notification-broadcasting.md
Created February 11, 2024 13:27
Optimal method for swiftly broadcasting database notifications in Laravel

Put this into event service providor's boot method

public function boot(): void
{
    // Observe the DatabaseNotification model for created events
    DatabaseNotification::observe(new class {
        
        // Listen to the created event 
        public function created(DatabaseNotification $notification): void
@jeromeabel
jeromeabel / 0.responsive-images.md
Last active August 17, 2025 21:29
Responsive images with srcset and sizes attributes

Responsive images

Aka "Do we need a PhD to add images on websites ?"

I focus here on reponsive images. Loading and accessibility topics are not detailed. For the purpose of the article, I've just used the <img> markup, but for real use cases, <picture> will fill all the needs.

Goal: to display elements consistently on screens with different densities

Setup

To test the following sections, you need to open Development Tools, and play with different screen sizes. Be aware that the browser keeps the last image in a memory cache, you should disable the cache or refresh the page to see your expected results.

@afiqiqmal
afiqiqmal / ImageMaliciousDetectionRule.php
Last active June 19, 2023 23:22
Simple Laravel Validation Rule for Image Content Validation.
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ImageMaliciousDetectionRule implements Rule
{
protected $malicious_keywords = [
'\\/bin\\/bash',
@sourovroy
sourovroy / languages.php
Last active November 25, 2023 14:58
PHP array to get the language by country locale.
<?php
return [
'bs' => 'Bosnian',
'ee_TG' => 'Ewe (Togo)',
'ms' => 'Malay',
'kam_KE' => 'Kamba (Kenya)',
'mt' => 'Maltese',
'ha' => 'Hausa',
'es_HN' => 'Spanish (Honduras)',
@calebporzio
calebporzio / PreviewOfUpcomingPackage.php
Last active December 2, 2024 12:10
A model trait that allows child models to use parent table names and relationship keys.
<?php
namespace App\Abilities;
use Illuminate\Support\Str;
use ReflectionClass;
/**
* Note: This is a preview of an upcoming package from Tighten.
**/
@vxnick
vxnick / gist:380904
Created April 27, 2010 15:52
Array of country codes (ISO 3166-1 alpha-2) and corresponding names
<?php
$countries = array
(
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',