Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
@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;
//...
}
@mathiasverraes
mathiasverraes / private_properties1.php
Created March 24, 2011 17:14
Access private properties of objects of the same class
<?php
class Foo
{
private $private;
public function __construct($value)
{
$this->private = $value;
}
public function getOther(Foo $object)
{
@mathiasverraes
mathiasverraes / listing1.php
Created May 17, 2011 19:44
Lazy Loading with Closures
<?php
// client code
$customer = $customerRepository->find($id);
$orders = $customer->getOrders();
@mathiasverraes
mathiasverraes / .bashrc
Created November 3, 2011 18:46 — forked from thomasvm/.bashrc
Git shortcuts
#! /bin/sh
alias gs="git status"
alias gc="git commit"
alias gr="git checkout"
alias ga="git add"
alias gl="git lola"
@mathiasverraes
mathiasverraes / .bashrc
Created November 3, 2011 18:46 — forked from thomasvm/.bashrc
Git shortcuts
#! /bin/sh
alias gs="git status"
alias gc="git commit"
alias gr="git checkout"
alias ga="git add"
alias gl="git lola"
@mathiasverraes
mathiasverraes / gist:1393879
Created November 25, 2011 16:10
Assert that two strings are close to each other. #phpunit
<?php
protected function assertStringDistanceInPercent($minimumPercentage, $expected, $actual)
{
$percentage = 0;
similar_text($expected, $actual, $percentage);
$this->assertGreaterThanOrEqual(
$minimumPercentage,
$percentage,
"The distance between the strings should be greater than or equal to $minimumPercentage%, got $percentage%");
@mathiasverraes
mathiasverraes / deps.ini
Created January 21, 2012 10:15
vendors script, replaces git submodules * MOVED TO https://github.com/Credico/git-dependency-manager *
; example deps.ini file
[twig]
git=http://github.com/fabpot/Twig.git
target=vendor/twig
version=v1.7.0
@mathiasverraes
mathiasverraes / keymastertest.html
Created April 5, 2012 07:46
angluar + keymaster + $location
<!doctype html>
<html ng-app>
<script src="http://code.angularjs.org/angular-1.0.0rc3.min.js"></script>
<script src="https://raw.github.com/madrobby/keymaster/master/keymaster.min.js"></script>
<script>
function HelloCntl($scope, $location) {
$scope.name = 'World';
$location.path('/foo');
key('x', function() {
console.log('x key pressed');
@mathiasverraes
mathiasverraes / gist:3046310
Created July 4, 2012 09:21
Display git branch in command prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
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\] \$ '