bad, { display: table } good

http://colintoh.com/blog/display-table-anti-hero

Dynamically Flip a Table (Interchange Rows and Columns)

Got a big table in a web page and would rather look at it with the rows and columns exchanged? i.e. If the headers are along the top, you’d rather they were along the left. Use this bookmarklet which asks for a (jQuery) CSS selector. The default CSS selector of “table” will flip the axes of every table on the page.

http://bookmarkify.it/41

If you don’t trust bookmarkify.it (but you do trust Google for the jQuery CDN), here’s some safe code:

javascript:var s=document.createElement('script');s.setAttribute('src','//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$(function(){javascript:$(prompt("Flip Table(s) with CSS selector","table")).each(function(){var e=[];$(this).find("tr").each(function(){var t=[];$(this).find("td,th").each(function(){t.push($(this))});e.push(t)});$(this).empty();var t=0;while(true){foundOne=false;var n=$("<tr/>");for(var r=0;r<e.length;r++){if(e[r].length>t){e[r][t].appendTo(n);foundOne=true}else{$("<td/>").appendTo(n)}}if(!foundOne){break}n.appendTo($(this));t++}})});

Variable and Fixed Time Steps in Games: Another Option?

In my experience, fixed time steps are predictable and easy to code. The biggest drawback I’ve found with using them is that, when choosing a frame rate, there’s a trade off between supporting less-capable hardware and providing nicely responsive player controls for twitchy games. Variable time steps seem daunting for my high school math skills; pretty much anything more advanced than integrating acceleration into position (s = v * t + 1/2 * a * t^2) means that I’m going to need to start buying math friends drinks to explain things to me.

My current strategy is to use variable time stepping for my player movement (running and jumping) and fixed time stepping for everything else (including enemy running and jumping). This means that I’ve used the above formula in my player update code: jumps are an impulse, but gravity, walking, and idle-drag are all accelerations. I’m clamping my variable time step range to between 30fps and 60fps and am testing my running and jumping mechanics by stepping forward with each of those time steps. By making sure that my jumps are the same height at both 30 and 60 fps, I feel comfortable assuming that wild things won’t happen between those two rates.

PHP: Pass an array by reference to a callback

If you try call_user_func($callback, &$array) you’ll get “Call-time pass-by-reference has been deprecated”.

The solution is to use call_user_func_array($callback, array(&$array)).

PHP sort return values

$fruits = array("lemon", "orange", "banana", "apple");
print_r(chain_user_func('sort', $fruits));

function chain_user_func() {
$args = func_get_args();
$func = array_shift($args);
$args[0] = &$args[0];
call_user_func_array($func, $args);
return $args[0];
}

Network Solutions FTP censorship

A funny thing happens if you try to upload a file to a Network Solutions FTP site with the following string in it:

.addcslashes(htmlspecialchars

The FTP session times out and the file is only partially written. A simple solution is to add whitespace:

. addcslashes(htmlspecialchars

Go figure.

Inheritance is overrated; prefer composition wherever it makes sense.