Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
<?php
mb_internal_encoding("UTF-8");
function λ($fn) {
list($args, $body) = explode('=>', $fn, 2);
$args = trim($args);
$args = ltrim($args, '(');
$args = rtrim($args, ')');
@yreynhout
yreynhout / ProjectorSyntax.cs
Created March 8, 2014 19:58
Playground for flavors of declarative projections in C# ... seeking the DSL so to speak
// 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
@docteurklein
docteurklein / extract.sh
Created December 2, 2011 16:43
extract non translated sentences in twig templates
find . -type f -name "*.html.twig" | xargs perl -pi -e "s/>([^\s<{>].*?)</>{{ '\1'|trans }}</g"
@psamatt
psamatt / car
Created November 21, 2013 21:49
DDD Car entity
<?php
namespace CoreDomain\Car;
class Car
{
private $id;
private $make;
private $model;
private $registrationNumber;
@esbullington
esbullington / d3-zoom-drag.md
Created October 15, 2012 14:38
easy d3 zoom and pan

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 + ")")
  )
)
<?php
// iterator impl:
class MapIterator extends IteratorIterator {
private $f;
public function __construct($f, $inner) {
parent::__construct($inner);
$this->f = $f;
@jcartledge
jcartledge / set.class.php
Last active August 9, 2020 18:25
PHP immutable set
<?php
function set() {
return new Set(func_get_args());
}
class Set implements Countable, Iterator {
private $data = array();
function __construct($data) {
@mathiasverraes
mathiasverraes / TestFrameworkInATweet.php
Last active May 23, 2022 12:28
A unit testing framework in a tweet.
<?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 January 19, 2024 10:47
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
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
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

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: