Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / min-max-array.php
Last active March 22, 2024 16:02
PHP - Find Min/Max Count in Multi-Dimensional Array
<?php
// @see: https://stackoverflow.com/questions/21861825/quick-way-to-find-the-largest-array-in-a-multidimensional-array
$array = [
['foo', 'bar'],
['foo'],
['foo', 'bar', 'baz'],
];
echo count(max($array)) . PHP_EOL;
echo count(min($array)) . PHP_EOL;
@ziadoz
ziadoz / BrowsingFailed.php
Last active March 18, 2024 17:43
Laravel Dusk Events
<?php
use Laravel\Dusk\Browser;
use Exception;
class BrowsingFailed
{
/**
* @param array $browsers array<\Laravel\Dusk\Browse>
*/
@ziadoz
ziadoz / FakesJavaScriptFetch.php
Last active March 7, 2024 11:05
Plain JS - Fake JSON Response From fetch()
<?php
namespace Tests;
use Laravel\Dusk\Browser;
trait FakesJavaScriptFetch
{
// Usage: $browser->script($this->fakeFetchResponse(['foo' => 'bar']));
public function fakeFetchResponse(array $data): string
{
@ziadoz
ziadoz / example.php
Last active February 23, 2024 13:26
Hypothetical PHP Getter/Setter Attribute Syntax
<?php
class Example
{
// By default the attribute binds a getter to `getName()`and setter to `setName()`.
#[Accessor]
protected string $name;
// Custom getter and setter method names can be passed.
#[Accessor(getter: 'customGetter, setter: 'customSetter')]
protected string $name;
@ziadoz
ziadoz / PreventMaxInputVarTruncation.php
Created February 2, 2024 15:17
Laravel 10.x - max_input_var INI Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
class PreventMaxInputVarTruncation
@ziadoz
ziadoz / index.html
Created January 31, 2024 09:57
JS - Custom Events
<a href="#">I am a link.</a>
<script>
document.addEventListener('DOMContentLoaded', () => {
const a = document.querySelector('a');
['load', 'click'].forEach((type) => {
a.addEventListener(type, (event) => {
event.preventDefault();
console.log(event.type);
});
@ziadoz
ziadoz / MyTest.php
Created January 31, 2024 09:27
Laravel - Modify Route Controller for Testing
<?php
namespace Tests;
use App\Controllers\MyController;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use Tests\TestCase;
class MyTest extends TestCase
@ziadoz
ziadoz / Laravel-Container.md
Last active January 30, 2024 16:18 — forked from zhilinskiy/Laravel-Container.md
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@ziadoz
ziadoz / index.html
Created January 26, 2024 17:46
HTML/CSS/JS Transition Height Slide
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
div.filters {
background: #999;
display: grid;