Skip to content

Instantly share code, notes, and snippets.

View sebdesign's full-sized avatar

Sébastien Nikolaou sebdesign

View GitHub Profile
@sebdesign
sebdesign / CollectionContains.php
Created January 15, 2021 23:30
assertCollectionContains
<?php
namespace Tests;
use Illuminate\Database\Eloquent\Model;
use PHPUnit\Framework\Constraint\Constraint;
/**
* Constraint that asserts that the Collection it is applied to contains
* a given value.
@sebdesign
sebdesign / AppServiceProvider.php
Created February 7, 2018 15:48
Fix Carbon localization
# app/Providers/AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Carbon;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@sebdesign
sebdesign / OutputBuffer.php
Created October 2, 2017 19:47
Testing ZlibOutputStream
<?php
namespace Amp\ByteStream;
use Amp\Promise;
class OutputBuffer implements OutputStream, Promise {
private $contents;
/** @var \Throwable Used to fail future writes on failure. */
@sebdesign
sebdesign / collection-invoke.php
Last active November 7, 2016 15:37
Collection macro for invoking methods on (nested) items
<?php
use Illuminate\Support\Collection;
/**
* Invoke the method each (nested) item of the collection, returning the result of each invoked method.
*
* @var string $method The method or the path of the method separated with @.
* @var mixed $arguments,... Any optional arguments to pass to the invoked method.
* @return static
@sebdesign
sebdesign / Color.php
Last active September 28, 2024 14:50
<?php
class Color
{
/**
* Convert a hex color to RGB.
*
* @param string $hex #BADA55
* @return array{int,int,int} [186, 218, 85]
*/
@sebdesign
sebdesign / curry.php
Created October 27, 2015 20:02
PHP Curry
<?php
function curry(callable $function)
{
$args = array_slice(func_get_args(), 1);
return function() use ($function, $args) {
return call_user_func_array($function, array_merge($args, func_get_args()));
};
}