Skip to content

Instantly share code, notes, and snippets.

<?php
define('FLAG_0', 1);
define('FLAG_1', 2);
define('FLAG_2', 4);
define('FLAG_3', 8);
/**
* Will fail when setting multiple flags at once
*/
@leihog
leihog / flattr5.php
Created November 29, 2010 15:58
wordpress flattr plugin quick fix
<?php
class Flattr
{
const VERSION = '0.9.18';
const WP_MIN_VER = '2.9';
const API_SCRIPT = 'api.flattr.com/js/0.6/load.js?mode=auto';
/** @var array */
protected static $categories = array('text', 'images', 'audio', 'video', 'software', 'rest');
@leihog
leihog / xmltoarray.php
Created December 14, 2010 13:30
Very basic class to convert simple xml snippets in to arrays.
<?php
/**
* (extremely) simple class to convert a DOMNode to an array.
* @todo Add support for attributes, namespaces and other goodies...
*/
class XmlToArray
{
/**
* Checks if node has any children other than just text
*
@leihog
leihog / vhosts.sh
Created July 25, 2011 07:28
Lighttpd include all vhosts in path in to lighttpd.conf
#!/bin/bash
#
# Use this to include all vhost files in to lighttpd.conf
# In lighttpd.conf add the line: include_shell "/etc/lighttpd/vhosts.sh"
#
VHOST_PATH="/etc/lighttpd/vhosts/*"
for f in $VHOST_PATH
do
cat $f
diff --git 0.11/access/macro.py 0.11/access/macro.py
index 7ea2e23..70ed06f 100644
--- 0.11/access/macro.py
+++ 0.11/access/macro.py
@@ -11,6 +11,7 @@ import re
from trac.core import *
from trac.wiki.api import IWikiMacroProvider
from trac.wiki.formatter import format_to_html
+from trac.perm import PermissionSystem, IPermissionStore
@leihog
leihog / todo.vim
Created February 17, 2012 13:29
Barebones example of how to make a simple vim syntax file.
" Barebones example of how to make a simple vim syntax file.
" Language: todofile
" Maintainer: leihog
"if exists ("b:current_syntax")
" finish
"endif
let b:current_syntax = "todo"
" v:folddashes a string that contains dashes to represent the foldlevel.
@leihog
leihog / main.php
Created May 14, 2012 07:22
loadModules() for modular habari plugins
<?php
class MyPlugin extends Plugin
{
private $modules = array();
private function loadModules()
{
$base_path = dirname(__FILE__) . '/modules/';
$dh = opendir( $base_path );
@leihog
leihog / colorize.php
Created June 28, 2012 13:38
colorize function in PHP
<?php
function colorize($str, $fg = 'white', $bg = false)
{
$fg = str_replace(array('-','_'), '', $fg);
switch($fg) {
case 'black': $fg = "0;30"; break;
case 'yellow': $fg = "1;33"; break;
case 'brown': $fg = "0;33"; break;
case 'green': $fg = "0;32"; break;
@leihog
leihog / gist:3749523
Created September 19, 2012 13:01
Fix Shatter(Steam version) on OS X - Indie Humble bundle 6
Start Terminal.app and then type:
$ cd ~/Library/Application Support/Steam/SteamApps/common/Shatter/Shatter.app/Contents/Frameworks/Cg.framework
$ ln -s Versions/1.0/Cg Cg
@leihog
leihog / nodejs.yml
Created May 9, 2014 12:50
Example Ansible playbook for installing node.js from source
- hosts: all
vars:
node_version: "0.10.28"
tasks:
- name: Check for node.js
shell: test "$(node -v 2> /dev/null)" = v{{node_version}}
register: nodejs_installed
ignore_errors: True
tags:
- nodejs