Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
{-# LANGUAGE ExistentialQuantification #-}
module Beauforma where
import qualified Data.Map.Strict as M
data Event =
GuestBookedAppointment {
appointmentId :: Guid,
guestId :: GuestId,
appointmentDateAndTime :: DateTime,
@mathiasverraes
mathiasverraes / LeSighTest.php
Created June 30, 2016 12:48
PHP string casting
<?php
final class FuckYouPHPTest extends \PHPUnit_Framework_TestCase {
/** @test */
public function should_fail () {
new WantsAString(new NotAString());
// Fails as expected
}
/** @test */
@mathiasverraes
mathiasverraes / Maze.hs
Last active August 4, 2016 17:40
initial PoC for a maze game in Haskell
module Lib where
import Data.List.Split
import System.Random
a4by4Maze :: Maze
a4by4Maze = Maze [
[(╝),(╦),(╝),(╣)],
[(╩),(╣),(╗),(╝)],
[(═),(╩),(║),(╝)],
@mathiasverraes
mathiasverraes / zeromq.md
Last active September 23, 2021 13:29
zeromq php7
git clone git://github.com/mkoppanen/php-zmq.git
cd php-zmq
phpize && ./configure
make && make install

Finally add the following line to your php.ini:

@mathiasverraes
mathiasverraes / Workflow.hs
Created August 16, 2016 08:45
haskell (publishing) workflow experiment
module Workflow where
import Data.Maybe
import Data.Set
newtype State = State String deriving(Ord, Show, Eq)
type States = Set State
data Action = Action String deriving(Eq, Show)
type Workflow = [Transition]
data Transition = Transition {
@mathiasverraes
mathiasverraes / MonoidalFizzBuzz.hs
Created November 16, 2016 16:21
Extensible Monoidal FizzBuzz in Haskell
module MonoidalFizzBuzz where
import Data.Monoid
import Data.Maybe
-- based on @mittie https://twitter.com/mittie/status/798257339736453120
monoidalFizzbuzz = zipWith fromMaybe numbers strings
where
fizzes = cycle [Nothing, Nothing, Just "Fizz"]
buzzes = cycle [Nothing, Nothing, Nothing, Nothing, Just "Buzz"]
@mathiasverraes
mathiasverraes / instanceof.php
Last active November 24, 2016 18:14
Instanceof rant
<?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
}
@mathiasverraes
mathiasverraes / file.php
Created November 24, 2016 18:24
faking method overloading
<?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
}
@mathiasverraes
mathiasverraes / ducktyping.php
Created November 24, 2016 18:55
duck typing
<?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 / water.php
Last active July 19, 2018 05:23
Water Kata
<?php declare(strict_types = 1);
function volume (array $levels) {
return array_sum(
zipWith(
'subtract',
zipWith(
'min',
scanl('max', $levels),
scanr('max', $levels)