Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Nikolaou sebdesign

View GitHub Profile
@sebdesign
sebdesign / CollectionContains.php
Created Jan 15, 2021
assertCollectionContains
View CollectionContains.php
<?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.
View AppServiceProvider.php
# 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 Oct 2, 2017
Testing ZlibOutputStream
View OutputBuffer.php
<?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 Nov 7, 2016
Collection macro for invoking methods on (nested) items
View collection-invoke.php
<?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
View Color.php
<?php
class Color
{
/**
* Convert a hex color to RGB.
*
* @param string $hex #BADA55
* @return array [186, 218, 85]
*/
View curry.php
<?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()));
};
}