Skip to content

Instantly share code, notes, and snippets.

Mathias Verraes mathiasverraes

View GitHub Profile
@yreynhout
yreynhout / ProjectorSyntax.cs
Created Mar 8, 2014
Playground for flavors of declarative projections in C# ... seeking the DSL so to speak
View ProjectorSyntax.cs
// TState is an individual, immutable state entry in the projection state
// Flavor 1:
Projection<TState>.
When<TEvent>.ThenAdd<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> handler).
When<TEvent>.ThenUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TState, TEvent, TState> handler).
When<TEvent>.ThenAddOrUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> addHandler, Func<TState, TEvent, TState> updateHandler)
When<TEvent>.ThenRemove<TKey, TEvent>(Func<TEvent, TKey> selector)
// TState is an individual, immutable state entry in the projection state
// Flavor 2: Add & Update melted into Set leaving the host to deal with Add or Update semantics
View lambda.php
<?php
mb_internal_encoding("UTF-8");
function λ($fn) {
list($args, $body) = explode('=>', $fn, 2);
$args = trim($args);
$args = ltrim($args, '(');
$args = rtrim($args, ')');
@mathiasverraes
mathiasverraes / TestFrameworkInATweet.php
Last active Mar 18, 2020
A unit testing framework in a tweet.
View TestFrameworkInATweet.php
<?php
function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);}
@ToJans
ToJans / InventoryItems.hs
Last active Mar 26, 2018
Haskell implementation of Greg Young's CQRS sample: https://github.com/gregoryyoung/m-r Love the sheer elegance of Haskell; no need for all that infrastructure crap
View InventoryItems.hs
module InventoryItems(Command(..), Event(..), handle) where
import Data.Maybe(isJust)
type Id = String
type Name = String
type Amount = Int
data Command = CreateInventoryItem Id
| RenameInventoryItem Id Name
View iterator-vs-generator.php
<?php
// iterator impl:
class MapIterator extends IteratorIterator {
private $f;
public function __construct($f, $inner) {
parent::__construct($inner);
$this->f = $f;
@psamatt
psamatt / car
Created Nov 21, 2013
DDD Car entity
View car
<?php
namespace CoreDomain\Car;
class Car
{
private $id;
private $make;
private $model;
private $registrationNumber;
@jcartledge
jcartledge / set.class.php
Last active Dec 19, 2015
PHP immutable set
View set.class.php
<?php
function set() {
return new Set(func_get_args());
}
class Set implements Countable, Iterator {
private $data = array();
function __construct($data) {
@esbullington
esbullington / d3-zoom-drag.md
Created Oct 15, 2012
easy d3 zoom and pan
View d3-zoom-drag.md

I know a lot of people have trouble zooming and panning d3. Indeed, I found myself in a situation where I had a simple bar chart to which I wanted to add the zoom behavior, and also make the full chart draggable. I saw several extremely complex examples of d3 charts with zooming and panning, and thought that there must be an easier way, particularly if you don't need to scale the x and y axes. There is, and here is is in CoffeeScript:

vis.call(d3.behavior.zoom()
  .on("zoom", ->
    g.attr("transform", "translate(" + d3.event.translate[0] + "," + d3.event.translate[1] + ") scale(" + d3.event.scale + ")")
  )
)
@jimbojsb
jimbojsb / gist:1630790
Created Jan 18, 2012
Code highlighting for Keynote presentations
View gist:1630790

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:

@docteurklein
docteurklein / extract.sh
Created Dec 2, 2011
extract non translated sentences in twig templates
View extract.sh
find . -type f -name "*.html.twig" | xargs perl -pi -e "s/>([^\s<{>].*?)</>{{ '\1'|trans }}</g"
You can’t perform that action at this time.