Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
<?php
final class Basket implements RecordsEvents
{
private $basketCanOnlyContainFiveProducts;
private function __construct()
{
$this->basketCanOnlyContainFiveProducts = new BasketCanOnlyContainFiveProducts();
}
@mathiasverraes
mathiasverraes / gist:b557d4013718a905d8b7
Created August 15, 2014 09:32
The Little Schemer continuation example ported to Erlang
-module(bla).
-compile(export_all).
a_friend(_, []) -> false;
a_friend(_, _) -> true.
main() ->
multiremberco(tuna, [strawberries, tuna, swordfish], fun a_friend/2).
multiremberco(_Atom, [], Cont) ->
@mathiasverraes
mathiasverraes / lambdalicious.php
Created November 17, 2014 09:13
Lambdalicious blog post
<?php
require_once __DIR__ . 'path/to/src/Verraes/Lambdalicious/load.php';
assert(
isatom(@my_atom)
);
atom(@my_atom);
assert(
isatom(my_atom)
<?php
require_once __DIR__ . '/../src/Verraes/Lambdalicious/load.php';
// non generic, only deals with functions with arity=2
function curry($f) {
return function($x) use($f) {
return function($y) use($f, $x) {
return $f($x, $y);
};
};
<?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: