Optimizing JavaScript for extreme performance and low memory consumption

Tags:

While making WidgetCity, I had to use various measures to speed up the code. In this post, I’ll show you the tricks I learned – some of which I haven’t seen mentioned anywhere else before.

A lot of performance optimization tips for JavaScript code involve things that you more typically see in web sites, like minimizing the amount of DOM modifications. But this case was different in that it was the script itself that had to run faster – it didn’t work with the DOM or anything, just processed a lot of data.

Read More

I wrote a Sim City clone in JavaScript

Tags:

This is why I haven’t been updating lately: I have been working on a Sim City clone, written purely in HTML, CSS and JavaScript!

The game is called WidgetCity, and I’m participating with it in the Betavine Widget Competition 2009.

The game was designed to run in Opera Widgets mode, but it also works in Firefox – only downside is that you can’t save your city. Get the widget here, or if you don’t have Opera, you can play the game here. There is also a help file.

Continue reading to find out more details about the game’s inner workings and such!

Read More

PHP Magic Features

Tags:

I wrote an article for Packt Publishing about PHP’s magic features: Magic functions, methods and constants.

The article has now been published on Packt’s website, and you can read it here!

Do you know a build tool?

Tags:

Do you have a repetitive task for example in a programming project? Chances are you could automate the steps with a build tool.

For example, in one of my JavaScript projects I had to do the following:

  1. Put all project files to a zip file: Click each file and each dir, and choose add to zip
  2. Rename the zip file, and click yes to tell windows I’m sure I want to do that
  3. Send the zip file to my server with sftp, and click yes to confirm overwriting the file

This isn’t such a complex task, but when I had to do it every time I needed to test a small change, it quickly started to consume more time and got repetitive.

Read More

Making a custom front controller in Zend Framework

Tags:

Firstly, apologies for the lack of posts lately. I’m pretty busy with various things right now, so I don’t have much time for blogging. Hopefully I’ll have some pretty interesting/cool stuff to show you later, though!

Now, here’s something interesting I spotted recently: Creating a custom front controller for Zend Framework.

Federico Cargnelutti is writing a series of posts on this topic at his blog, and it is definitely worth checking out.

Here are the posts he’s written so far:
Implementing your own Front Controller in Zend Framework
An Alternative to Zend_Controller: Introduction
An Alternative to Zend_Controller: The Router

Integrating FCKeditor with Zend_Form

Tags:

How to use FCKeditor, or any other WYSIWYG editor, with Zend_Form? Another relatively common question.

There are many ways you can do this, but let’s look at these two as they are the best in my opinion:

  • Adding some JavaScript to your view script
  • Creating a Zend_Form_Decorator

We’ll be using FCKeditor, but you can apply the techniques shown to others, such as TinyMCE, as well.

Read More

Using a builder to construct complex classes

Tags:

Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters.

Having something like that can make it more difficult to understand the code. In a case like this, you may want to consider using a builder class, which is kind of like a factory, but focused on just creating a single object. It can also be used to hide which concrete class the code is actually using by abstracting the construction.

Let’s take a look at the builder pattern in PHP. We’ll even get to use some chaining – everyone loves chaining, right?

Read More

Site update: Added Articles section

Tags:

I’ve added a brand new Articles section to the codeutopia.net website. Its purprose is to make it easier to find information on specific topics from the blog.

I’ve written a lot of posts, and it can be difficult to find interesting ones by just searching or browsing the blog archives. The articles section groups most of my posts into a main category and a sub category, making it easier to find posts about similar topics.

Head over to the articles page, and leave a comment here about what you think!

User-interfaces: why Gears of War 2 is easier to play than others?

Tags:

Most games on consoles are easier to play for a beginner, than their PC versions. This is due to various factors, but I think it’s mostly because it’s easier to get into the game on a console than installing, learning the controls and all on a PC.

Let’s take a look at Gears of War 2, as it has one exceptionally clever UI trick even when comparing to other console games.

Read More