Skip to content

Instantly share code, notes, and snippets.

View shadowhand's full-sized avatar
🚲

Woody Gilk shadowhand

🚲
View GitHub Profile
" force utf-8 mode
scriptencoding utf-8
" i got 99 problems, but utf-8...
set encoding=utf-8
" https://github.com/junegunn/vim-plug
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
<?php
declare(strict_types=1);
namespace Acme\Domain\Type;
use function Assert\that;
class EmailAddress
{
/** @var string */
@shadowhand
shadowhand / # php - 2018-04-04_13-56-32.txt
Created April 4, 2018 19:05
php on macOS 10.13.3 - Homebrew build logs
Homebrew build logs for php on macOS 10.13.3
Build date: 2018-04-04 13:56:32
@shadowhand
shadowhand / array_chunk_fixed.php
Created May 25, 2017 03:01
Array chunking for SplFixedArray
<?php
// Copyright (c) 2017 Woody Gilk (@shadowhand)
// MIT License
/**
* A chunking function for SplFixedArray
*
* Operates the same as array_chunk() but without $preserve_keys, for obvious reasons.
*
<?php
namespace Acme;
use Bcn\Component\Json\Reader;
use Generator;
class JsonStreamParser
{
/**
@shadowhand
shadowhand / NamedDTO.php
Created December 10, 2016 02:59
Using named constructors for data transfer objects
<?php
namespace Acme;
class DataTransfer
{
public static function forUser(
$user_id
) {
return new static($user_id);
@shadowhand
shadowhand / session-life-cycle.md
Created November 29, 2016 19:22 — forked from mindplay-dk/session-life-cycle.md
Complete overview of the PHP SessionHandler life-cycle

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@shadowhand
shadowhand / NamedCallable.php
Last active November 18, 2016 17:54
Execute any method, static or instance, as a callable
<?php
namespace Acme;
class NamedCallable
{
private $invoke;
private $prefix;
public function __construct(callable $invoke, callable $prefix)
@shadowhand
shadowhand / RouteInterface.php
Last active May 16, 2017 13:24
Routing interfaces for standards discussion
<?php
interface RouteInterface
{
/**
* Get the HTTP method this route handles.
*
* @return string
*/
public function getMethod();
// current proposal
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
// ...
return $delegate->process($request);
}
// alternative
public function process(ServerRequestInterface $request, DelegateInterface $next)
{