Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
@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 / 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 / phonenumbers.hs
Last active September 30, 2015 08:22
Phone Number Kata
-- Given a list of phone numbers, determine if it is consistent.
-- In a consistent phone list no number is a prefix of another. For example:
-- Bob 91 12 54 26
-- Alice 97 625 992
-- Emergency 911
-- In this case, it is not possible to call Bob because the phone exchange
-- would direct your call to the emergency line as soon as you dialled the
-- first three digits of Bob's phone number. So this list would not be consistent.
@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\] \$ '
@mathiasverraes
mathiasverraes / gist:3273994
Created August 6, 2012 12:09
Show the release notes using git
git log --pretty=oneline --no-merges COMMIT..COMMIT
@mathiasverraes
mathiasverraes / getclass.js
Created October 13, 2012 10:50
get the class of a javascript object
var getClass = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
// define a class
function Animal() {}
// do this for all classes that need the getClass() method