Monthly Archives: February 2007

javascript beautifier

I’ve written a JavaScript beautifier (JBeauty), for fixing the indentation (and other features) of code to my own preferences.

click here to try it

What it solves, is that sometimes I have to work with other peoples’ code, which is sometimes … “ugly” is the kindest word I can think of. This application cleans up the code, keeping comments intact, and formatting it based on my own rules, which are:

  • use tabs for indentation
  • no unneeded white-space (“if ( a == b )” is a waste of bandwidth compared to “if(a==b)”)
  • blocks begin with ‘{‘ which starts on the same line as whatever opened the block (“if(a==b){\n” instead of “if(a==b)\n{\n”

Simple rules, but they make me happy.

At some point, I might extend it to fix missing semi-colons (reasons I don’t like “optional” semi-colons).

Whatcha think? Anything you’d like to see in it? Does it screw up with your code?

moving and speaking and stuff, oh my!

Lots of news.

Jareth, my three-year-old mute genius, who can draw houses and write whole alphabets in lower case or upper case, and can also write “daddy”, “mammy”, “jareth” and “boann” from memory (as well as the word “color”, which we will forgive him for (he’s too young to know how wrong Merkin spelling is)) – has said his first word.

Yesterday, he said the word “Two”. And it wasn’t a fluke occurance. When asked what each of a group of numbers was, he would “um-hmm” for every one of them except 2, which he would consistently speak.

Yesterday as well, we got word that the sale for our new house has gone through, so we will be out of our present one within a few weeks. It’s a massive house compared to all the previous places I’ve lived – two storeys with a converted attic, making four bedrooms, and something like five toilets (one for each work day). It’s in a perfect location as well – well off any busy road, so it will be safe to let Jareth out playing in the summer.

we’re in number 16 or 17 or something
two and a half floors of goodness

I bought Bronwyn a laptop, as she kept complaining when I brought mine to work, as she likes to sit in her armchair and read her Grahom Coxon and knitting forums. The machine I got her is twice as fast, and has more than twice the RAM and HD space as mine, and all she uses it for is her poxy forums! I want it! I could use the power!

Her machine has Vista on it as well. I’ll leave it on it to teach her a lesson… when the viruses start infecting her machine, I want her to appreciate it when I install Linux on it 🙂

After setting up her machine, I must admit, Vista is pretty polished-looking. Although – is that all?? After five years of development, you’d expect a bit more than just some glossy window decorations. After Bronwyn had gloated about how Vista looked, compared with my machine, I installed a Beryl theme which emulated the same decorations, but in a free and secure operating system.

Vista? Hah! We shall see… *steeples fingers*

KFM 0.8

function getKfmFile(version){
var lang=document.getElementById(‘lang’).value‘’+lang,’kfm’,’modal,width=700,height=500′);

Demo English



download it at the KFM website

New Features

  • New language: Romanian (thanks to Andrei Suscov)
  • Return thumbnails to the opener (35, 142)
  • Tag engine (12, 13, 143), allowing files to be categorised, and searched by category.
  • Client-side syntax highlighted text editing (125, 126) using CodePress.
  • Rename multiple files (103). This allows you to select a group of files, and rename them all to a common format.


  • Multi-line captions (89)
  • ImageMagick used where possible (152, 111), allowing huge images to be edited without PHP running out of memory.
  • KFM will return either a normal URL (155), or a URL which allows the get.php script to be used to retrieve the file. The advantage to using get.php is that in the future, we will be able to apply authentication, so only authorised users can read a file. This also allows thumbnails to be built on-the-fly.
  • The database tables can use a specified prefix now (129).
  • Double-click can be configured to either send the file back to the opener (FCKeditor, your CMS, etc), or to open the file directly (120).
  • config.php split into two files, allowing easier upgrades (146).
  • when moving through files with the arrow keys, the selected file will always be visible (110).
  • KFM can now be used to manage multiple sites through one instance (154).
  • A metrics logger has been added (134). This will allow us to know what versions of KFM are in use, and whether it is safe to deprecate certain features if need be.
  • Comments can now be extracted from .gif files to be used as captions (88).
  • Documentation written on how to transfer a KFM archive from one machine to another (161).
  • Many bug fixes (159, 97, 156, 149, 68, 157, 147, 148, 144, 102, 145, 118, 140, 141, 98, 139, 135, 150, 151, 165, 167, 164, 162, 160, 113, 163).
  • Some ideas were rejected (112, 21, 131, 19, 18).

As usual, this release has been helped along by the many testers in the forum, testers who have contacted me by email, and all of the translators.

Very large thanks to Benjamin Ter Kuile, who has been very actively hacking away at the KFM code and produced such gems as the CodePress integration.

a little php challenge

Yesterday, I was helping to tutor a temp worker in PHP. As a challenge, I gave him the task of starting with this string:


… and using that to generate this table:


I might have chosen a difficult one, though, as he gave up after a while. I’ve thought of several ways of doing it – here’s the one I explained to him:


foreach($rows as $k=>$v){
    foreach($cells as $k2=>$v2)$cells[$k2]='<td style="background:#'.($v2=='0'?'fff':'000').'">&nbsp;</td>';
echo '<table>'.join('',$rows).'</table>';

I was thinking about it in off-moments throughout the day – what is the shortest piece of code which will produce the same table?

Here’s another variant I wrote this morning:


echo '<table><tr>'.join('</tr><tr>',str_split(preg_replace('/([f0])/','<td style="background:#\\1\\1\\1">&nbsp;</td>',strtr($str,'01','f0')),312)).'</tr></table>';

That’s 244 characters in length. Keeping the first three lines intact, can you improve on this?

a few questions

What is energy made of? When someone says “that has potential energy”, or “electrical energy” or “nuclear energy”, you know exactly what they mean, but what is energy actually made of? Can you extract energy from some action and show it to someone? Can you draw energy? Possibly a silly question… – maybe “energy” is an example of a “meta-attribute” (something which does not physically exist, but only exists in context)

Why does refraction happen?The usually metaphor used to describe refraction is a model car rolling along on a smooth surface like Lino, and encountering a rougher surface such as carpet, at an angle. Because a car is multi-dimensional in shape, part of the car will move onto the carpet before the rest, which causes that part to slow down, which causes the entire car to turn towards that side of the car (thus, the car is “refracted” by the carpet). Light, however, is usually portrayed as a single point which is travelling really fast. Does a point have sides? When entering a refractive object, can part of a photon be said to be “in” the slower medium, while the rest is still outside? If so, then I understand refraction, but it seems to me that light needs to be explained a bit more clearly in school…

Is the speed of light a constant or not? There have been reports of scientists recently slowing light to a crawl. Surely, that makes the speed of light a variable? Or, is c (the letter used to describe light-speed in physics) not actually “the speed of light”, but “the maximum speed of light”?

When approaching the speed of light, does “time” actually slow? It seems to me that if the speed of light is the fastest speed possible, then that can cause perceived time dilation while moving, without inventing actual malleable time. For instance, imagine a simple action such as passing a cup from one hand to another. Easy – takes a second. However, imagine you are now sitting in a spaceship travelling at the speed of light. Logically, you cannot now pass a cup from hand to hand, as simple vector math will show that be doing that, the cup will actually be travelling faster than c. Similarly, if perceived time depends on, say, an electron “ticking” around an atom, then at the speed of light, time must seem to stop altogether, as the electron will not be able to orbit the atom, as part of that orbit will be travelling faster than c. (similarly, as you /approach/ c, time will appear to “slow down”, when in fact, it just takes longer to perform any task, including thinking)

Am I wrong? Enquiring minds want to know…