Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
@mathiasverraes
mathiasverraes / with_stashes.sh
Last active June 23, 2018 14:12
Show git branch name on command prompt. Put this in your ~/.bash_profile or whatever your OS uses, then restart your terminal and cd to a git folder. It should look something like: yourname@machine /path/to/project [my-branchname] $ UPDATE: the `with_stashes.sh` version also shows the number of entries in your git stash on the command prompt. Sc…
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
# git branch on command prompt
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\w\[\033[01;35m\]$(parse_git_branch)\[\033[01;34m\] \$ \[\033[00m\]'
else
PS1='\[\033[01;31m\]\u@\h \[\033[01;00m\]\w\[\033[00;33m\]$(parse_git_branch)\[\033[00m\] \$ '
fi
<?php
class Thing
{
/**
* @JMS\Type("integer")
*/
private $fooBar;
public function getFooBar()
@mathiasverraes
mathiasverraes / PassThroughNamingStrategy.php
Created March 15, 2013 13:03
JMSSerializer PassThroughNamingStrategy
<?php
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
use JMS\Serializer\Metadata\PropertyMetadata;
class PassThroughNamingStrategy implements PropertyNamingStrategyInterface
{
/**
* Translates the name of the property to the serialized version.
*
#!/bin/bash
phpunit
EXIT_CODE="$?"
if [ $EXIT_CODE -eq "255" ]; then
# Wrapping the error code to 1, so bisect marks this build as "bad" and continues.
exit 1
fi
@mathiasverraes
mathiasverraes / functional.js
Created October 2, 2013 06:49
@MikeBild posted this on twitter. As an exercise, I made the same thing in an FP style, using recursion instead of mutable state. It's slightly longer :-) Because there's no native pattern matching, I have a calc/2 (public) and a calcX/3 (private) function. https://twitter.com/mikebild/status/385276260089225216
'use strict';
var assert = require('assert');
var _ = require('lodash');
var calcX = function (acc, coinSizes, totalAmount) {
if (coinSizes.length == 0) return acc;
var currentCoinSize = _.head(coinSizes);
@mathiasverraes
mathiasverraes / CoupleMaterialToAvailableActivityCommandHandlerTest.php
Created October 18, 2013 10:08
PHPUnit + Prophecy vs PHPUnit + PHPUnit MockObject
<?php
namespace Model\WeekPlanning\Tests\Activity;
use Dsp\CoreBundle\Entity\FosUser;
use Dsp\CoreBundle\Entity\School;
use Dsp\CoreBundle\Tests\DspTest;
use Dsp\MaterialsBundle\Entity\Material;
use Dsp\MaterialsBundle\Entity\MaterialRepository;
use Dsp\MaterialsBundle\Entity\OwnedMaterial;
@mathiasverraes
mathiasverraes / gist:7813235
Last active December 30, 2015 09:59
Another iteration of my bio for conferences...

Twitter bio:

Student of Systems • Meddler of Models • Labourer of Legacy

Bio:

Mathias Verraes is a recovering music composer turned programmer, consultant, blogger, speaker, and podcaster. He advises companies on how to build enterprise web applications for complex business domains. For some weird reason, he enjoys working on large legacy projects: the kind where there’s half a million lines of spaghetti code, and nobody knows how to get the codebase under control. He’s the founder of the Domain-Driven Design Belgium community. When he’s not working, he’s at home in Kortrijk, Belgium, helping his two sons build crazy Lego train tracks.

<?php
// iterator impl:
class MapIterator implements Iterator {
private $f;
private $inner;
public function __construct($f, $inner) {
$this->f = $f;
@mathiasverraes
mathiasverraes / even_shorter.js
Last active December 31, 2015 22:49
fizzbuzz in javascript with and without lodash (probably works with underscore as well)
for(i=0;i<100;console.log(++i%15?i%5?i%3?i:f='Fizz':b='Buzz':f+b));
@mathiasverraes
mathiasverraes / example.php
Created January 9, 2014 14:17
Translating Value Objects ---- In response to https://gist.github.com/wkocmann/4f6843e15db5401cdefc
<?php
final class Country
{
private $isoCode; // private! Value Objects are immutable
public function __construct($isoCode)
{
$this->isoCode = $isoCode;
}