I had 2 hours to kill so I thought I’d write a LOLCode interpreter.
I know there’s already a few LOLCode interpreters around, but I couldn’t help myself. Plus I’ve always been interested in interpreter design.
It’s still a work in progress at this stage, so a lot of the language hasn’t been fully implemented.
Here are two working programs…
Hello World
BTW the classic hello world program
HAI
VISIBLE "Hello world!"
KTHXBAI
Output:

Accepting User Input
HAI
VISIBLE "Hello there, what is your name?!"
I HAS A NAME ""
BTW ask for the users name
GIMMEH NAME
BTW welcome the user
VISIBLE "Welcome to LOLCode " N NAME N "!"
KTHXBAI
Output:

If you’re addicted to reddit.com like me, you’ll understand my frustration with all those Ron Paul links. Especially if you don’t live in the US, and don’t really know who the guy is.
If anyone is interested, I’ve written a small Greasemonkey script which hides all reddit links that include the text “Ron Paul”.
To install, download the Greasemonkey file and drag it onto your firefox window.
ronpaul.user.js
Here’s a quick tip for working with the command line in PHP.
If you’ve ever run a PHP script via the command line, you would have noticed that output from the script is not printed until the script has finished.
If you need your output displayed in real time, you can open a stream to the command line…
$stdout = fopen('php://stdout', 'w');
Simply write any output to the stream and it will be printed on the command line in real time…
fwrite($stdout, "Hello CLIn");
One thing I keep noticing is the use of background noise or clutter in CAPTCHAS. It’s now well known in the OCR (Optical Character recognition) field that background noise can be easily removed by computers. It’s basically useless at hindering spam bots.
It’s so easy that I was able to clean the following CAPTCHA up in only 20 lines of PHP code.
Here’s how…
At a glance, you can see the CAPTCHA’s background noise has a blue tint.
Looking at the RGB value of the image in Photoshop, I can see that all parts of the background have a blue value higher than 180.
That’s the only piece of information needed to remove the background.
The code simply loops through every pixel of the image and checks the RGB value of it. If the blue (B) value is higher than 180, color it white.
Here’s the final image. The characters can now be easily separated and identified using OCR software.
So you can see why most background noise is basically useless in CAPTCHAS.
Ray Casting is a extremely fast method of generating 3D images using high-school level mathematics.
Remember playing Wolfenstein 3-D? This was one of the first games made using the ray casting technique.
The graphics in Wolfenstein don’t even come close to today’s gaming standards; but it was still impressive for it’s time. It was also fast, considering the speed of the hardware it ran on.
Although ray casting is an outdated method, it’s a good introduction to 3D imagery and game design. It’s also quite easy to recreate yourself (if you can remember pythagoras theorem).
The basic idea of ray casting is very simple. To transform a 2d image map into a 3d representation, “rays” are projected from the viewer towards the light source. If a ray hits an object on the 2d map, a vertical line is drawn on our “3d” image to represent this section of the wall or object. Think of the image as vertical slices.
This diagram might do a better job of explaining.
Textures can be applied using texture maps but unfortunately other effects like reflections aren’t so easy to create. They can be faked though.
If you’ve got nothing to do for a few hours, consider creating a simple ray cay caster in your favourite language.
Here’s a few resources to get you started.
Most developers have now heard about Facebook’s leaked index.php source code, which was anonymously posted here. If you haven’t seen it already, there are a number of links listed on Techcrunch.
I’ve seen a few bloggers criticize Facebook developers for using procedural programming rather than classes and object oriented techniques. I’m not exactly sure why they’ve chosen to develop the site like this; but I am going to take a guess and say it was to improve speed and efficiency.
Object oriented programming was first introduced to PHP in version 4. However, the language wasn’t originally designed around objects and classes, so the implementation was clunky and awkward. This meant that procedural code was often much faster than object oriented code.
Considering the size and popularity of social networks, I’m not surprised they chose procedural code over objects. That tiny boost in performance would easily outweigh the advantages of using classes.
Fortunately, most (if not all) issues with objects have been solved in PHP 5, which is now closer to a truly object oriented language.