Skip to content

Instantly share code, notes, and snippets.

View mathiasverraes's full-sized avatar

Mathias Verraes mathiasverraes

View GitHub Profile
@mathiasverraes
mathiasverraes / phplint.sh
Created July 12, 2012 07:42
Recursive PHP Lint script
#!/bin/bash
for file in `find .`
do
EXTENSION="${file##*.}"
if [ "$EXTENSION" == "php" ] || [ "$EXTENSION" == "phtml" ]
then
RESULTS=`php -l $file`
@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
@mathiasverraes
mathiasverraes / promises.md
Created October 22, 2012 18:26 — forked from domenic/promises.md
You're Missing the Point of Promises

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
});
@mathiasverraes
mathiasverraes / class-based.js
Created October 29, 2012 08:47
Javascript Dependency Injection using partial functions
// CommandHandler Class
var CommandHandler = function(repository) {
this.handle = function(command) {
// do stuff with repository and command
}
}
// Elsewhere, create an instance of the class...
var myCommandHandler = new CommandHandler(repository);
$jim_price = $hannah_price = new Money(2500, new Euro);
@mathiasverraes
mathiasverraes / index.html
Created November 6, 2012 17:18
D3 barchart with groups
<!DOCTYPE html>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<style>
svg {
font: 10px sans-serif;
shape-rendering: crispEdges;
<?php
class Foo
{
private function __construct(){}
public static function create($bar)
{
$instance = new static;
$instance->bar = $bar;
}
}
@mathiasverraes
mathiasverraes / MoneyType.php
Created January 8, 2013 16:11
Doctrine2 DBAL type to store Money objects in a single field.
<?php
namespace Money\Doctrine2;
use Money\Money;
use Money\Currency;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
@mathiasverraes
mathiasverraes / .gitconfig
Created January 10, 2013 20:39
Bart's Pimping Git Log
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative