Skip to content

Instantly share code, notes, and snippets.

View hugowetterberg's full-sized avatar

Hugo Wetterberg hugowetterberg

View GitHub Profile
@hugowetterberg
hugowetterberg / Shapes.json
Created January 8, 2010 22:13
Probably of limited interest for other people, but this is a small recipe for turning svg paths into chipmunk consumable shape coordinates using python and xslt. The svg was created using the GLIPS Graffiti editor http://glipssvgeditor.sourceforge.net
{
"player": [
[
0.0,
0.0
],
[
10.0,
-30.0
],
@hugowetterberg
hugowetterberg / custom_merge_recursive.php
Created January 8, 2010 08:28
A less useless recursive merge of arrays
<?php
/*
* As you probably know array_merge_recursive() is pretty useless. This is a function
* that I always tend to write when working with recursive merges of arrays.
*
* See output.txt to see the difference in behaviour.
*/
function custom_merge_recursive(/* $a, $b, $c, ... */) {
$args = func_get_args();
@hugowetterberg
hugowetterberg / menu_local_task.tpl.php
Created December 3, 2009 11:15
Template for local tasks that preserves destination
<?php
$match = array();
if (preg_match('/<a\shref="([^"]+)"(\s([a-z]+)="([^"]+)")?>([^<]+)<\/a>/', $link, $match)) {
$parts = parse_url($match[1]);
$path = trim($parts['path'], '/');
$opt = array();
if (!empty($_GET['destination'])) {
$opt['query']['destination'] = $_GET['destination'];
@hugowetterberg
hugowetterberg / FollowAction.h
Created November 30, 2009 07:18
Cocos2D action that makes a node move towards a specific point at a set speed
//
// FollowAction.h
// Battle Pong
//
// Created by Hugo Wetterberg on 2009-11-29.
// Copyright 2009 Good Old. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "cocos2d.h"
<?php
$ops = array(
array('operation' => 'insert'),
array('operation' => 'update'),
array('operation' => 'update'),
array('operation' => 'update'),
);
$ops2 = array(
array('operation' => 'update'),
@hugowetterberg
hugowetterberg / decay.php
Created October 21, 2009 13:59
Computing score changes based on half-life
<?php
$half_time_24h = pow(0.5, 1/24);
$total = 1000;
$score = 700;
$last_update = time() - (3600*1.5); // One and a half hour ago
$new_total = 1010;
$total_delta = $new_total - $total;
$hour_delta = (time() - $last_update) / 3600;
<?php
function db_query_debug($sql, $parameters) {
global $db_prefix;
$sql = preg_replace('/\{([^\}]+)\}/', $db_prefix . '$1', $sql);
if (!is_array($parameters)) {
$parameters = array_slice(func_get_args(), 1);
}
$args = array_merge(array($sql), $parameters);
$q = call_user_func_array('sprintf', $args);
<?php
/**
* Returns all the layers in the tile service.
*
* @return array
*/
function simplegeo_tileservice_get_layers() {
static $layers;
$cache_key = 'simplegeo_tileservice:layers';
#!/usr/bin/env php
<?php
$content = file_get_contents($argv[1]);
function invert_color($matches) {
$r = 255 - intval(substr($matches[1], 0, 2), 16);
$g = 255 - intval(substr($matches[1], 2, 2), 16);
$b = 255 - intval(substr($matches[1], 4, 2), 16);
$a = isset($matches[2]) ? $matches[2] : '';
<?php
// Add the css file as you would have added a normal
// css file in template.php, but pass the path
// through cssdry_stylesheet().
if (module_exists('cssdry')) {
drupal_add_css(cssdry_stylesheet(drupal_get_path('theme', 'a_theme') .'/css/style.css'), 'theme');
}