Skip to content

Instantly share code, notes, and snippets.

@mattijs
mattijs / printf.js
Created March 1, 2012 10:03
JavaScript printf
// GNU C printf for JavaScript
// http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output
//
// Syntax
// % [ param-no $] flags width . * [ param-no $] type conversion
// Parts
// -----
// Zero or more flag characters that modify the normal behavior of the conversion specification.
@mattijs
mattijs / .zshrc.local
Created February 6, 2012 11:21
todo command for zsh using t.py
# t.py wrapper ---------------------------------------------------------------
todo() {
if [ -f "$(pwd)/todo" ]; then
python ~/bin/t.py --task-dir . --list todo $@
else
echo "No todo file found in this directory. Run 'touch todo' to create a new todo list."
fi
}
@mattijs
mattijs / gist:1058095
Created July 1, 2011 08:30
Browser Side Event Emitter
/**
* Small EventEmitter implementation borowed from MicroEvent.js
*
* MicroEvent.js: https://github.com/jeromeetienne/microevent.js
*/
var Emitter = function(){};
Emitter.prototype = {
on: function(event, fct){
this._events = this._events || {};
this._events[event] = this._events[event] || [];
@mattijs
mattijs / cm.coffee
Created April 20, 2011 13:18
Coffeescript module singleton
{EventManager} = require 'events'
class CloudManager extends EventEmitter
constructor: (@config) ->
# Do some stuff
instance = null
module.exports = {
@mattijs
mattijs / random_background.py
Created April 9, 2011 13:11
Change the Gnome desktop background to a random image from a directory
#!/usr/bin/env python
# This script will change the desktop background to a
# random image taken from a directory
#
# Use random_background.py --help for options
#
# Author: Mattijs Hoitink <mattijs@monkeyandmachine.com>
# License: none (public domain)
import sys, argparse, os, mimetypes, re, random, gconf
@mattijs
mattijs / random_background.py
Created April 9, 2011 11:21
Change the Gnome desktop background to a random image from a directory
#!/usr/bin/env python
# This script will change the desktop background to a
# random image taken from a directory
#
# Use random_background.py --help for options
#
# Author: Mattijs Hoitink <mattijs@monkeyandmachine.com>
# License: none (public domain)
import sys, argparse, os, mimetypes, re, random, gconf
@mattijs
mattijs / nerf.js
Created April 3, 2011 06:49
Send request and print response using node.js
var util = require('util');
var fs = require('fs');
var http = require('http');
// Check for an input file
if (2 >= process.argv.length) {
console.error('An input file must be specified');
process.exit(1);
}
@mattijs
mattijs / chopQueryString.php
Created October 31, 2010 21:47
Break down a query string in PHP 5.3 using an anonymous function
$chop = function($query) {
parse_str($query);
unset($query);
return get_defined_vars();
};
$query = $chop("catid=1&follow=false");
#!/bin/sh
# Quick script for discovering and installing PHPUnit
# For real speed use the following command:
# wget http://gist.github.com/raw/521622/e5eb07769f21bef858ec062dd43bd4686021e8ca/phpunit_install.sh -O - | sh
echo "This will install PHPUnit on your machine"
echo ""
echo "+ Discovering pear channels for PHPUnit"
echo "====================================="
pear channel-discover pear.phpunit.de
function _getElementsByClassName(DOMNode $node, $class)
{
$elements = array();
if (XML_ELEMENT_NODE === $node->nodeType && $node->hasAttributes()) {
for ($i = 0; $i < $node->attributes->length; $i++) {
$attribute = $node->attributes->item($i);
if ('class' === strtolower($attribute->name)) {
$values = explode(' ', $attribute->value);
if (in_array($class, $values)) {