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.

The Solution to Unique Passwords

This is not the bookmarklet. This is where you will find the bookmarklet. WordPress doesn’t allow the hosting of bookmarklets. Click here.

  1. Drag this bookmarklet to your bookmarks (put it somewhere you can click it easily, and consider renaming it to something shorter)
  2. Whenever you need a password, click the bookmarklet
  3. You must always enter the same Passphrase and you should keep it secret
  4. You’ll always get the same generated password for the same Passphrase and Domain
  5. If you need a password for a service that spans hostnames (e.g. mail.google.com, docs.google.com) you’ll need to enter the same thing in the Domain popup for each (e.g. google) so you get the same password
  6. If you click on the password field before the bookmarklet, the password will be automatically typed in for you

Sha256 Implementation by Chris Veness under the LGPL 2.1. I guess that makes this LGPL too.

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
  /*  SHA-256 implementation in JavaScript | (c) Chris Veness 2002-2010 | www.movable-type.co.uk    */
  /*   - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html                             */
  /*         http://csrc.nist.gov/groups/ST/toolkit/examples.html                                   */
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
  

array_flatten() in PHP

$arrays ? call_user_func_array(‘array_merge’, $arrays) : array()

How to sort a PHP array-of-arrays

array_multisort(
array_pluck($records, 'field_to_sort_on'), SORT_ASC,
//array_pluck($records, 'another_field_to_sort_on'), SORT_ASC,
//array_pluck($records, 'another_field_to_sort_on'), SORT_DESC,
$records
);

/*

NOTE: this requires array_pluck():

function array_pluck($recordList, $targetField) {
$result = array();
foreach ($recordList as $recordKey => $record) {
if (!array_key_exists($targetField, $record)) { continue; }
$result[ $recordKey ] = $record[$targetField];
}
return $result;
}

*/

Design a site like this with WordPress.com
Get started