Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
<?php
$dispatcher = new EventDispatcher;
class SendWelcomeEmail implements QueuedEventHandler {
public function when(Event $event) {
// delegate to whenUserHasRegistered, whenFoo..
}
private function whenUserHasRegistered(UserHasRegistered $event) {
@mathiasverraes
mathiasverraes / max.php
Created December 9, 2014 19:40
max($list, $function) in php
<?php
// test data
class Foo {
private $a;
private $b;
function __construct($a, $b)
{
class MyClass
{
/**
* Lots of comments
*/
public function importantMethodAtTheTop()
{ // braces on new lines
// lots of newlines to create structure
@mathiasverraes
mathiasverraes / zendhttp.php
Created January 19, 2015 13:15
Bug in Zend HTTP?
<?php
$request = \Zend\Http\Request::fromString(
<<<REQ
GET /?foo=bar HTTP/1.1\r\n\r\n
REQ
);
var_dump($request->getQuery()->get('foo'));
// Expected "bar", got null
@mathiasverraes
mathiasverraes / gist:ce93e6aa7dd7db75d772
Last active August 29, 2015 14:15
Add the requester's repo as a remote to yours - github

GitHub provides a special pulls remote "namespace" on the upstream repo, so you can add it as a fetch pattern to your .git/config like so:

    [remote "upstream"]
      url = https://github.com/neovim/neovim.git
      fetch = +refs/heads/*:refs/remotes/upstream/*
      fetch = +refs/pull/*/head:refs/pull/upstream/*

Then when you git fetch --all, you will have ALL pull requests available in your local repo in the local pull/ namespace. To check out PR #42:

@mathiasverraes
mathiasverraes / Collatz.hs
Created September 9, 2015 18:30
Collatz sequences in Haskell using a Writer monad. Not that you need one. For science!
module Collatz where
import Control.Monad.Writer
collatzSeq :: Integer -> Writer [Integer] Integer
collatzSeq n = do
n <- collatz n
if n==1 then return 1 else collatzSeq n
collatz :: Integer -> Writer [Integer] Integer
@mathiasverraes
mathiasverraes / declarative_code.hs
Last active September 11, 2015 12:33
Testing fizzbuzz
-- in reaction to http://codemanship.co.uk/parlezuml/blog/?postid=1325
-- oneHundredIntegersSeparatedByCommas
-- integersDivisibleByThreeReplacedWithFizz
-- integersDivisibleByFiveReplacedWithBuzz
-- integersDivisibleByThreeAndFiveReplaedWithFizzBuzz
-- remainingNumbersAreUnchanged
-- Imho No amount of tests can explain fizzbuzz better than a declarative implementation:
fizz :: Int -> String
@mathiasverraes
mathiasverraes / BankAccount1.php
Created March 21, 2011 13:52
Interface Discovery with PHPUnit's Mock objects
<?php
class BankAccount
{
private $twitter;
public function __construct(Twitter $twitter)
{
$this->twitter = $twitter;
}
public function deposit($amount){
}
<?php
/** @Entity */
class Bug
{
/** @Column(type="integer") */
private $id;
/** @Column(length=50) */
private $status;
//...
}