Coding…
I’ve been doing a bunch of PHP stuff lately. One interesting project is the template engine, which has seem some really awesome progress over the last weeks. But more on that later…
Something else I’ve tried out a few days ago is using memcached. Memcached is a small server program that runs in the background (as a service on Windows machines, or as a daemon on Linux) and uses spare RAM to store data. It can also run distributed, with a bunch of servers all throwing their spare memory into a big pool which can conveniently be accessed as if it was on a single machine. PHP has a standard plugin that can communicate with memcached – what can you do with that, you wonder? Well, as the name suggest, memcached is a cache which stores data (in key/value) pairs in memory. Basically your script can store data in it so you don’t have to fetch it from the database (saving you from executing a time-consuming query and putting load on the database server).
It is actually quite efficient – all of the world’s big websites (especially a lot of social networks and such) use it. Some sites even have massive amounts of servers dedicated to it. In such setups getting everything right is tricky (you want to be sure that everything is consistent – with a large distributed system it’s easy for something to go out of sync, potentially causing a lot of trouble), but it is quite useful.
I played with it for a bit and it turns out that memcached is really very easy to work with. Installation on my Windows box was a matter of putting the executable in a folder and running it command-line with a few options that make it install itself as a service, after which it is permanently available; accessing it from PHP takes no more than adding a standard plug-in to your php.ini file, restarting Apache, and calling the right functions. It’s actually very easy to work with. A quick measurement told me that, when loading some configuration data using memcache vs. loading it from the database, doing it from memcache is actually twice as fast – and that’s for a trivial task.
Unfortunately you’re not going to get memcached support with any basic shared hosting plans (and VPSes generally don’t have the spare memory capacity). It takes a bunch of setting up, securing, and firewalling to make it run securely in a live environment and you can’t let multiple users share the same memcached host without them being able to access eachother’s data. It’s a bit of a downside, but memcached was never intended to be used in a shared environment, so it’s not a big deal.
The project I’m working on right now is actually getting full-blown memcache support, so it will cache anything that can reasonably be cached (within configurable limits), making the whole thing run faster and using far less database queries.
Next up, the template engine. I’ve already written a template engine quite a while ago (several actually) – but I wanted to make some improvements and ended up rewriting most of it. If you don’t know, a template engine essentially separates presentation and program logic, which is very useful if you want to encrypt the actual PHP code without removing the ability to edit the HTML, or just generally to organize things – it makes it very easy to figure out where you need to be to change something, and even non-programmers can easily edit the layout of the page this way.
The previous incarnation of my engine supported variables and blocks. Variables are well, variables, and blocks can either be repeated any given number of times (the contents of variables can be varied for each instance – so this is what you would use to fill a table with data, for instance) or entirely hidden. This is sufficient in a lot of cases, but I wanted to add more: conditional statements, loops (other than repeated blocks), proper caching, and so on.
Previously, all parsing was done in the final processing function, which did everything by reading files and releasing a bunch of string manipulation functions on them. It worked, but the code was complicated as fuck and debugging (let alone adding something new) is a whole new kind of hell by itself. The new version uses a system not unlike what a compiler for, say, C, does: it splits the input data (the template file(s)) into a bunch of tokens (textual data, variables, blocks, etcetera), runs a lexical analysis check (grammar basically – make sure that the end if your if statement does not precede the actual if statement, for instance), and finally, goes over the list of tokens (using a specialized stack), combining it with the dynamic data (contents of variables, block instances, etcetera) to produce output.
That all sounds terribly complicated, and well, it is. One major advantage though is that now 90% of the processing effort (parsing and analyzing the template) can be stored for later use, and the engine does that either by files, or by sending the data to memcached (the latter being preferred, since it doesn’t involve hard drive activity, which is relatively slow). The result is a very powerful and fast system, in which it is actually possible to add a new feature, should the need for it arise.
The whole beast has a ton of features – variables (both local and global), blocks (plus ‘empty blocks’, something that gets shown if there are no instances of the block), conditional statements (if/elseif/else – admittedly expression handling is very basic at the moment, but that’s for future improvement), caching, variable modifiers, a bunch of debug features, tools like optionally stripping HTML comments from the final output – and the whole thing weighs in at ‘only’ 2650 lines of code (including tons of comments and whitespace) / 73.2 kilobytes (all in a single file). It’s definately not finished yet, but I’m quite satisfied already
Oh, and also, I now use NuSphere PhpED. Most of the time, IDE’s mostly manage to annoy the crap out of me, but this one actually works instead of being a constant pain in the ass. I’d definately recommend it.
Dvorak
This night I took all off my keyboard for a good cleaning. While I was at it, I re-arranged the keys to the Dvorak layout (which did require me to cut a few small pieces of plastic, but hey, it all fits and works now). And if I end up not using it too much, it’s okay since I can type in QWERTY blind (and really fast).
So, right now I’m typing REALLY slowly… But I’ll get used to it. My speed (and average amount of time spent searching for each letter) has already decreased significantly while I wrote this post – I can already find some letters blind (especially the ‘A’) – or at least, without spending half an hour searching for it
No, my experience in typing with Dvorak does not extend very far beyond this post… But practice makes porfect, and I am already noticing that the letters are arranged in a more logical way
Dragons
Today I read that Bioware officially announced Dragon Age 2, sequal to Dragon Age: Origins. Yay!
I’m quite excited about this. I really liked DO:A (and hence did two playthroughs, despite the amount of time it takes to get through the storyline). Even though in some cases I got the feeling that everything was deliberately made more difficult to lengthen the game rather than to add something to the overall storyline, it’s one of only a few games that managed to really grasp my attention in the last year or so. So that is pretty damn good.
DA:O Awakening (the expansion) was good too – rather short compared to the original campaign, but definately enjoyable!
And to all people who whine about how there is too much dialogue and interacting with NPCs and having to deal with the storyline:
That’s the whole f*cking point of an RPG.
If you don’t like dialogue, then go play a shooter or something. Or Pong. I don’t care.
Politics
Politicians really remind me of little school children sometimes. Or well, actually, they do that most of the time.
We had the elections a few weeks ago. From the election came certain results about which party gets how many seats. Can we please just have those people sit down in their expensive blue chairs and let them talk about stuff and vote against eachother to make whatever decisions it is the government needs to make? As far as I recall that is the entire idea of our democratic system, so let that be what they do. Not this childish bullshit they’re wasting time on now.
We had elections, we have results – take those, accept them, live with it, and just do your freakin’ jobs.
“But mommy, I don’t want to play with that kid! He’s mean!”
Politicians, stop whining and grow up already.
Seriously.
Spam
Yay for social networks!
I just sent someone 24 messages in a row, detailing my adventures in eating two slices of bread
Turn-ons
Edited (yes, using Paint, of course) from today’s C&H comic:

I wanted to give the guy on the left a nice little leather suit, but my paint skills just aren’t THAT epic.
I am currently using this as MSN picture, waiting how long it takes until people are going to give me weird responses… We’ll see
Pulse of the Beast
I just had to share this…
I am now ranked 666th of the world on WhatPulse!

For those of you who are not familiar with it, WhatPulse counts mouseclicks, keystrokes, and tracks the distance you move your mouse. This data is then sent to a central server, where statistics and ranking lists are created. Is it useful? No, not really. But is it fun? Hell yes!
And you don’t even need to do anything extra for it (which is why I’ve been running it for a few years now). It is impressive that the Netherlands as a country is ranked second of the world, even though our country is tiny!
Anyway, if you aren’t using WhatPulse yet, get it now!
File of Holding
After recovering some data from a damaged USB stick, I found a very curious file…

I want more of those!
Towels
To all the froods who really know where their towel is…
I wish you a very happy Towel Day!
May DNA never fade from our memories, and let us never forget the importance of towels, a greatly under-appreciated not-quite-household object.
A Story
Once upon a time, in a land that doesn’t actually exist but for the purposes of this story we will imagine that it does, there lived, a boy. This boy, was not a special boy in pretty much any imaginable way. He had the average size, weight, and appearance for a boy of his age, and was not particularly smart (or stupid). His name was Vroomp, and like most boys of his age, he served in the King’s army, as boys of his age were required to do.
The reason that the King had chosen to enlist even young boys into the army, was the raging war with a neighbouring country. The war had been going on for so long that nobody really remembered what the war was about, or even what the name of the country was – most of the time they were referred to simply as ‘the neighbours’ or ‘the enemy’. This has not in any way anything at all to do with the author of this story being too lazy to come up with any sort of decent-sounding name.
The King had a problem. His armies were vastly superior to the Neighbour’s army in many ways. They had a superior number of limbs that were capable of wielding weapons, superior training, superior numbers, pretty much everything about them was better. Except, their strategies.
Somewhere in the beginning of the war, an advisor to the King had invented Science. This granted him a lot of useful knowledge, a very well-paying job at the local college, a lot of respect from his friends and families, and generally a lot of other good things. The King naturally saw the potential advantage in using his knowledge in the war, so he asked his advisor to devise a new strategy to use against their hated enemy.
The good man went to work, and came up with a plan. The plan went something like this:
“As all of you know, the Heisenberg Uncertainty Principle says, in simple terms, that you can never be really sure where something is,” he explained.
“And since when you don’t know where something is in the first place, the best idea is to either go searching for it (which is futile, since you’ll never find out where it is anyway), or consider whatever it is you were looking for to be lost and hope to find it again at a later point in time.”
That wasn’t the brilliant part just yet.
“Everybody knows that, when you have lost something, it tends to come back to you at the time you least expect it.”
Now, let’s apply that knowledge to the neighbour’s army and defenses.
“Since it is impossible to know where their armies are and they can therefore be considered lost, and because in the middle of a direct assault on their territory is pretty much exactly when you would find some sort of resistance, it is, in accordance with my theory, perfectly safe to charge in at any moment. We don’t even need to bring weapons. We’ll just march in and there won’t be anyone there to defend against us. The only time when you would actually run into them is when you really wouldn’t expect it to happen, say, when you’re sitting against a tree thinking trying to figure out what the baby from a nineteen-legged squirrel and a shopping basket would look like.”
Amazed by the brilliance, the King dispatched his armies straight away.
Needless to say, the result of the battle was less than impressive. In a few hours, very little remained of the once mighty army, and shortly after that, a little bit less remained of the connection between the Scientist’s head and the rest of his body.
Centuries later, however, the war was still raging on. The only reason that the aggressors of the great slaughtering all those many years ago had not been defeated yet, was that the Enemy was a species that was generally very calm and peaceful and felt very bad about having to wipe out an army of such nice young lads.
At this point you have probably forgotten entirely about Vroomp. Though, admittedly, there is nothing really special about him, as has been said before. In an attack during one of the later years of the war (the new strategy involved bringing weapons to the battle), Vroomp and the rest of his squad charged into an enemy encampment. Being the young inexperienced boy he was, Vroomp drew his sword, grabbed an arrow, and spent a few seconds trying to figure out how to combine the two items into something useful, or at least, something edible. Then, in a rather painful fashion, he discovered that swords are meant to by themselves, by the simple fact that one was dividing his favorite vital organ into a few more pieces than what was generally accepted as being a good number of pieces to have your vital organs in.
A few years later, the King’s armies finally perished, and the King was forced to surrender what little he had left. He spent his remaining years hiding himself in places so distant and strange that even he himself started to believe that his entire kingdom and everything that had gone down was nothing more than a vague dream from a distant past.
The Neighbours (which is not really a proper term anymore since they were now the sole country that existed, but ‘Enemy’ is probably an even worse term since that obviously does not apply anymore) lived in peace and prosperity.
Until a lonely man somewhere in the Neighbour’s country had invented Science again.
The rest, as they say, is history. What has passed since then I will leave up to your own imagination (but feel free to share any very creative suggestions with me
).
Will Possibly Be Continued…

