Skip to content

Instantly share code, notes, and snippets.

@stubbetje
stubbetje / debug.unusedstylesheets.js
Created February 16, 2009 16:01
create list of unused stylesheet rules
// create list of unused stylesheet rules
$(document).ready(function()
{
var sel = [];
for( var s = 0 ; s < document.styleSheets.length ; s++ ) {
var rules = document.styleSheets[s].cssRules || document.styleSheets[s].rules;
for( var r = 0 ; r < rules.length ; r++ ) {
@stubbetje
stubbetje / pretty_shell.sh
Created April 23, 2009 08:20
show git branch and dirty state in bash prompt
#!/bin/bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/';
}
parse_git_dirty() {
[[ ! $(git status) =~ "nothing to commit (working directory clean" ]] && echo " ⚡ "
}
export PS1='\[\033[01;30m\] [$(parse_git_branch)\[\033[01;33m\]$(parse_git_dirty)\[\033[01;30m] \[\033[00m\]'$PS1
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
<?php
/**
* simpele gradient image adhv GET parameters
*
* @author Stefan Stubbe
*/
// default settings definiëren
$defaults = array(
@stubbetje
stubbetje / autorun.php
Created September 4, 2009 21:56
autorun.php: run a command on file modifications
#!/usr/bin/env php
<?php
/* original version can be found at https://gist.github.com/181172 */
if( ! function_exists( 'inotify_init' ) ) {
die_with_error( 'This script needs the inotify module' );
}
$excludePatterns = array(
@stubbetje
stubbetje / base64.js
Created November 9, 2009 14:34
Base64 encode and decode in javascript
var Base64 = {
characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ,
encode: function( string )
{
var characters = Base64.characters;
var result = '';
var i = 0;
do {
@stubbetje
stubbetje / SplClassLoader.php
Created November 11, 2009 09:12 — forked from jwage/SplClassLoader.php
SplClassLoader
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@stubbetje
stubbetje / ExampleController.php
Created April 6, 2010 14:34
Gorilla_Controller_Action_Helper_Resource
<?php
class Example_Controller extends Zend_Controller_Action
{
public function indexAction()
{
$db = $this->getHelper('resource')->db;
}
}
@stubbetje
stubbetje / gist:422106
Created June 2, 2010 08:28
flatten an multidimensional array and combine keys with separator
<?php
$flatten = function( $array , $keySeparator = '.' ) use ( & $flatten )
{
if( is_array( $array ) ) {
foreach( $array as $name => $value ) {
$f = $flatten( $value , $keySeparator );
if( is_array( $f ) ) {
foreach( $f as $key => $val ) {
$array[ $name . $keySeparator . $key ] = $val;
@stubbetje
stubbetje / error_levels.php
Created July 8, 2011 14:14
Show what error levels are included in a given error_reporting() value
<?php
if( $_SERVER['argc'] === 1 ) {
printf(
'No error level specified as argument (%s <errorlevel>), using current error_reporting value...' . PHP_EOL
, $_SERVER['argv'][0]
);
$errorlevel = error_reporting();
} else {