Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
@bxt
bxt / php-doc.mkd
Created March 6, 2011 23:59
List of phpdoc-like projects for generating documentation from javadoc-annotated php files

Since there's a lots of phpdoc-like php documentors and the like projects on the webs, and they are all named similar if not equal, I wanted to write a little overview:

phpdoctor of 02/2011

Currently using this, namespace support plus UML stuff.

phpdoctor of 01/2011

Didn't test it, looks good.

@bxt
bxt / static-non-static-mixing.php
Created March 12, 2011 18:44
Some code snippets demonstrating mixing of static and non-static contexts in PHP
<?php
class Foo {
public static function bar() {
echo "calling public static bar() in an ".(isset($this)?"object (".get_class($this).")":"static")." context. \n";
}
public function baum() {
echo "calling public baum in an ".(isset($this)?"object (".get_class($this).")":"static")." context. \n";
}
}
@bxt
bxt / jquery.fullscreenCanvas.js
Created March 14, 2011 21:58
Keep an html5-canvas element resized across the whole browser window
jQuery.fn.fullscreenCanvas = function() {
var els=this;
$(window).resize(function() {
els
.css({position:"fixed",left:0,top:0})
.attr("width",$(window).width())
.attr("height",$(window).height())
;
});
return this;
@bxt
bxt / Trojan.php
Created March 19, 2011 22:50
Odysseus forces Cassandra reveal her private nickname using horse. :D
<?php
class Trojan {
private $priv;
function __construct($priv) {
$this->priv=$priv;
}
function horse(Trojan $t) {
return $t->priv;
}
@bxt
bxt / 0-recur.php
Created March 26, 2011 20:55
A sample recursive php function producing excessive stack (from Common PHP)
<?php
/*
I wanted to know if it pays off to refactor some recursive code, and
if or not PHP does tail call optimization and i found this post:
http://commonphp.blogspot.com/2010/12/tail-call-optimization-in-php-53.html
A good place to check how much faster an itarative solution would be.
I started with executing the functions.
Result: PHP does not do TCO.
*/
@bxt
bxt / Nullcast.java
Created March 30, 2011 17:12
Casting null to Date in Java, avoiding ambiguous method calls
import java.util.Date;
public class Nullcast {
private static void foo(String bar) {
System.out.println("Not here...\n");
}
private static void foo(Date bar) {
System.out.println("Indeed here, even");
System.out.println((bar instanceof Date?"with Date":"without Date!"));
}
public static void main(String[] args) {
@bxt
bxt / ArrayObject.php
Created March 31, 2011 17:54
Access PHP-objects' getters and setter like an array
<?php
namespace bxt\Util;
class ArrayObject implements \ArrayAccess, \Iterator, \Countable {
private $object;
private $iterator=0;
private $offsetMethodMap=array();
private $offsetMethodMapSetters=array();
public function __construct($obj) {
$this->object=$obj;
@bxt
bxt / blender-render.sh
Created April 1, 2011 23:41
Blender from Command Line CLI sample call to render animation
for i in {1..61}; do echo rframe $i; time blender -b rotation1-mats.blend -f $i -o //rotation1_####.png -F PNG; done
# render frames 1 to 61, echo time for each frame and save them with specified filename
@bxt
bxt / sorting-jquery.js
Created April 11, 2011 23:04
Sorting HTML-Tables (or anything) using jQuery and Javascript's native Array.prototype.sort
var tableRows=$("tr").detach();
Array.prototype.sort.call(tableRows,function(a,b){
// Compare two table rows by the numeric value of their first <td>
return a.firstChild.firstChild.nodeValue*1 < b.firstChild.firstChild.nodeValue*1
});
$("table").append(tableRows);
// Tested in Firefox 4
@bxt
bxt / sketch_apr15b.pde
Created April 15, 2011 13:50
Processing sketch (Java-like) to display and experiment with various gradient methods
int barWidth=50;
GradientI[] grads=new GradientI[4];
void setup() {
size(1600, 300);
colorMode(HSB, 360, 100, 1.0);
noStroke();
background(0);
grads[0]=new LiearGradient(); /* lin */
grads[1]=new LiearGradient(1.1); /* clip_a */