Skip to content

Instantly share code, notes, and snippets.

Mathias Verraes mathiasverraes

View GitHub Profile
View maps_vs_models.md

https://twitter.com/janellekz/status/1183805720225107976?s=20

Well I know Simon's ideas on the matter, that's why I was asking for yours. I haven't given it enough thought to have strong opinions but here's a quick attempt:

Similar: Models and maps both consists of abstractions. The abstractions are chosen, for a purpose, in a context.

Different: Models are conceptual. Models are not just tools for understanding, they are understanding. I can draw or code or somehow express a model, but it's only a representation of an underlying model, not the model itself.

Landscapes and maps are physical. The symbols on the map are linked to things in the landscape. You don't visualize a map, the visualisation is the map.

@mathiasverraes
mathiasverraes / rollyourown.php
Created May 30, 2018
We don't need no DIC libs / we don't need no deps control
View rollyourown.php
<?php
// Context: I'm trying to argue that DI (and DIC) are great, and DIC libs suck.
// Happy to be proven wrong!
final class Router {
private $dependencies;
public function __construct (Dependencies $dependencies) {
$this->dependencies = $dependencies;
// You might say that this is Service Locator, but it's not. This router is toplevel,
// and toplevel must have access to dependencies. After that it can all just bubble nicely using proper DI.
@mathiasverraes
mathiasverraes / .gitignore
Created May 21, 2018
gitignore a folder except the gitignore file
View .gitignore
*
!.gitignore
@mathiasverraes
mathiasverraes / gist:b6673d1a1e010b2db0db46ac11eb80c8
Created Apr 23, 2018 — forked from jimbojsb/gist:1630790
Code highlighting for Keynote presentations
View gist:b6673d1a1e010b2db0db46ac11eb80c8

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@mathiasverraes
mathiasverraes / fib.php
Created Nov 14, 2017
Supposedly Lazy Fibonacci
View fib.php
<?php
foreach (fib() as $x) echo "$x\n";
function fib () {
yield 0; yield 1;
$f = fib(); $g = fib();
$g->next();
while (true) {
yield $f->current() + $g->current();
$f->next(); $g->next();
View Maybe.php
<?php declare(strict_types=1);
// In reaction to @marcoshuttle's http://marcosh.github.io/post/2017/06/16/maybe-in-php.html
// Warning: none of this code has been tested or even run.
namespace Verraes\Maybe;
interface Just extends Maybe {
// We can only extract if we know it's a Just
View water.php
<?php declare(strict_types = 1);
function volume (array $levels) {
return array_sum(
zipWith(
'subtract',
zipWith(
'min',
scanl('max', $levels),
scanr('max', $levels)
View ducktyping.php
<?php
// duck typing
final class Foo {
public function bar ($object) {
$object->quack();
}
}
// Because we know nothing about $object, it's only by calling quack that we can
// tell whether object supports quack()
@mathiasverraes
mathiasverraes / file.php
Created Nov 24, 2016
faking method overloading
View file.php
<?php
// method overloading example (not possible in php)
final class SomeEventListener {
public function when(EmployeeWasHired $event) {
// set a salary
}
public function when(EmployeeWasPromoted $event) {
// increase salary
}
View instanceof.php
<?php
final class Foo {
public function bar (AnemicObject $object) {
switch (true) {
case $object instanceof Alfa:
// do alpha shizzle
case $object instanceof Beta:
// do beta shizzle
}
You can’t perform that action at this time.