Posts about From the Laboratory

Introducing jsFrame

February 18th, 2009

Over the past few months I’ve become both more comfortable with Javascript and more impressed with what is possible with the language (more on that, with an example, in a few weeks). Doing lots of work with web application frameworks, I’ve become convinced that writing a framework entirely in Javascript would be both possible and useful. After meeting James Darling at UKGovWeb09 and checking out his Coup De website, I started considering the idea more seriously. I had a free day last Sunday and got coding. The result is jsFrame.

jsFrame is a web framework built entirely upon Javascript, HTML and CSS. It makes heavy use of Prototype.js and unlike some Javascript systems (such as coup-de) it uses the Model-View-Controller pattern and only loads Views as requested. This means that complicated applications are quite simple to develop, though it also means that simple pages take longer to load than they would with a normal website. I am particularly proud of the simply routing system, which is able to handle pretty URLs with a simple .htaccess file and my Javascript code. For more information, check out the demo site.

Non Javascript hackers can take several things away from this: the browser is becoming more and more the basis for rich web applications, and without Flash; network connections can still be a performance bottleneck despite faster connections, particularly on mobile browsers; reasonably advanced web projects can be executed in a short period of time. Oh, and I’m pretty handy with Javascript and web frameworks, and you might want to hire me!

Typecasting Strings to Integers in PHP

August 15th, 2008

PHP does some funny things when typecasting strings as integers and may not work the way you would expect (to be fair, it is documented). Here are some examples running under PHP 5.2.5 from the Mac OS X command line:

php -r 'var_dump((int) "agbae");'
int(0)
php -r 'var_dump((int) "zzzzzzzzzzzzzzzzzzzzzzz");'
int(0)
php -r 'var_dump((int) "2agbae");'
int(2)
php -r 'var_dump((float) "42165.6agbae");'
float(42165.6)

This is important to know because PHP allows you refer characters of strings just like you would the elements of an array (and somewhat similar to C’s strings):

php -r '$s = "abcdef"; var_dump($s[2]);'
string(1) "c"

However, giving an invalid key won’t given an error, depending on how your installation of PHP is configured in php.ini. If you give an out-of-bounds string you get an empty string:

php -r '$s = "abcdef"; var_dump($s[45]);'
PHP Notice:  Uninitialized string offset:  45 in Command line code on line 1
string(0) ""

If you give a string key, it is always for the zeroth index, since it is typecasted to an int and typecasting works as described above:

php -r '$s = "abcdef"; var_dump($s['zzzzz']);'
PHP Notice:  Use of undefined constant zzzzz - assumed 'zzzzz' in Command line code on line 1
string(1) "a"

Loading Javascript Libraries When Needed

June 23rd, 2008

Here is a nice little Javascript function to load some Javascript libraries:

function includeLibs()
{
var libs = [{object: 'Prototype', src: 'http://www.mobypicture.com/slideshow/prototype.js'}, {object: 'Lightbox', src: 'http://www.mobypicture.com/slideshow/lightbox.js'}];
for (var k = 0; k < libs.length; k++)
{
try
{
var obj = eval(libs[k].object);
}
catch (err)
{
var obj = false;
}
if (obj == false)
{
var newjs=document.createElement('script');
newjs.type='text/javascript';
newjs.src=libs[k].src;
document.getElementsByTagName('head')[0].appendChild(newjs);
}
}
}

This is particularly useful if you’re writing a widget that requires external libraries but the user might already have them loaded, such as Prototype.

Multilink

June 21st, 2008

Multilink is a very simple Javascript library that creates tooltips with multiple links per ‘normal’ link, its simplicity due to Prototip2 and Prototype. Why have one link when you can have ten! Check out the Multilink page for an example.

From the Laboratory: Closed Standards

May 27th, 2008

Closed standards are an oxymoron and any standard that is closed is moronic.

This is going to be a rant, so bear with me….

How can you call anything a standard when you don’t make the standard readily available? What is the point of a standard that no one can implement? Unfortunately, many ’standardized’ audio and video codecs are encumbered by patents, trademarks, and obscenely expensive reference documents. Surprise, surprise, but many of the telco standards bodies are the worst offenders! (As an aside, the movie people, thanks to MPEG, seem to be somewhat more sensible).

Read more »

From the Laboratory: IP2FireEagle

May 23rd, 2008

IP2FireEagle is small PHP script I wrote which will update your location in Yahoo Fire Eagle based upon your current IP address. You can find more information on the IP2FireEagle page.

From the Laboratory: Image Resizing and Thumbnail Creation

February 24th, 2008

This is the first in a series of posts on technical issues related to web site development and making user-friendly websites. These will focus on the technical details of developing web sites and applications so will probably be interesting to only a subset of readers. Within the next few months, time permitting, we will be launching a new section of the site called Bubble Foundry Labs, where you will be able to find both technical articles and experimental web applications. For non-technical types, these demo applications may prove easier to understand than this article series.

Read more »