Running Aptana Jaxer on Ubuntu 8.04

Posted June 5th, 2008 by Chris

I’ve not had any time to try out Jaxer yet, but the idea of a single platform for both client and server-side processing sounds good.

On trying to get started, though, one problem I encountered was that the installation instructions on Aptana’s site didn’t quite get Jaxer running on my default Ubuntu 8.04 install. The reason seems to be the built-in Apache trying to load an external library from

/usr/lib

which doesn’t exist.

The library in question is libexpat.so.0; however, there is a libexpat.so.1.5.2 installed! You can check this by running:

$ ls -l /usr/bin | grep libexpat

Creating a link to this file in /usr/lib with:

$ ln -s libexpat.so.1.5.2 /usr/bin/libexpat.so.0

seems to have got Jaxer running and the server status looks good. If you’re having trouble getting a Jaxer server running on the latest Ubuntu, this might be worth giving a go.

Tags: , , , ,
Posted in Personal, Programming, Uncategorized | 2 Comments »

Singleton Pattern in Javascript

Posted May 10th, 2008 by Chris

At work, I have been developing a custom framework loosely based on my experience with the symfony and Propel. One of the requirements for the application under development is to store the application’s state both on the server and the client, so that information can be passed by means of AJAX requests.

To aid this process, each page controller PHP class has a corresponding Javascript class. In order to maintain state through the application, each class as a Singleton. With the help of Prototype, singleton classes are quick and easy to implement in Javascript:

First, declare the class itself using Prototype’s Class.create() method:


PageController = Class.create({
	/**
	 * @type {integer}
	 */
	userId: null,
 
	// ... more properties ...
 
	/**
	 * Constructor
	 */
	initialize: function()
	{
	// ...
	},
 
	/**
	 * A method to do something...
	 */
	doSomething: function()
	{
		console.log('doSomething()');
	},
 
	// ... more methods ...
});

Once the class is created, we can declare a static instance of the class and a static method, getInstance(), that will be used to return the single instance of the class:


/**
 * @type {PageController} Static instance of the page controller
 */
PageController.instance = null;
 
/**
 * Return the static (singleton) instance of
 * the page controller object
 */
PageController.getInstance = function()
{
	if(!PageController.instance)
		PageController.instance = new PageController()
 
	return PageController.instance;
}

With the class now declared, the singleton instance can be accessed in your application using the static getInstance() method:


PageController.getInstance().doSomething()

Tags: , , ,
Posted in Personal, Programming, Uncategorized | No Comments »