iPhone v3 Rumor Round Up

June 4th, 2009

With WWDC 2009 just around the corner more and more bits of information are circling the web regarding a possible announcement for a new iPhone hardware revision. The folks at tgrblog.com have created this wonderful iPhone rumor round up graphic for you to digest. If these rumors are true I will be first in the queue at the Apple store to buy one.

iPhone Rumor Round Up

iPhone Rumor Round Up (Click to enlarge)

Cameron Gadgets, iPhone , ,

Getting Prototype.js and For…in statements to play

January 25th, 2009

I recently ran into a problem while trying to add the prototype.js library to one of my existing projects.

It turned out the issue was to do with for…in loops and Prototype.js extending the native objects with new properties.

Now for…in loops allow you to enumerate over an object, they kind of emulate for…each loops that you get in other languages like PHP.

Now the problem lies in that JavaScript has a major flaw, and it is that the for…in loops enumerate over not only the keys in your object but also the new prototyped methods.

For example:

var arr = new Array();
arr['name'] = 'Cameron'
arr['age'] = '28';

for(key in arr) {
alert(key + ': ' + arr[key]);
}

will output:

name: Cameron
age: 28

Adding the prototype.js library breaks the above example and causes the for…in loop to output the following:

name: Cameron
age: 28
each: function(iterator, context) {
    var index = 0;
    try {
      this._each(function(value) {
        iterator.call(context, value, index++);
      });
    } catch (e) {
      if (e != $break) throw e;
    }
    return this;
  }
eachSlice: function(number, iterator, context) {
    var index = -number, slices = [], array = this.toArray();
    if (number < 1) return array;
    while ((index += number) < array.length)
      slices.push(array.slice(index, index+number));
    return slices.collect(iterator, context);
  }
...

The above example output is shorted, when I ran the test it returned an additional 44 functions.

Obveously this is going to confuse any program you have that uses for…in loops.

So what’s the solution?

The following example fixes the problem:

var arr = new Array();
arr['name'] = 'Cameron'
arr['age'] = '28';

for(key in arr) {
if(arr.hasOwnProperty(key)) {
alert(key + ': ' + arr[key]);
}
}

In the above example we’ve added an IF statement that calls the hasOwnProperty method of the object we are enumerating passing the key as the first parameter. This method returns true if the object has the property specified and does not include properties that have been inherited through the prototype chain.

This method works in IE 6+, Safari 3.1+, Firefox 2+ and Opera 9.5.

So what about older browsers?

You can use the following almost as good method:

for(key in arr) {
if(typeof arr[key] !== 'function') {
...
}
}

Conculsion

As annoying as this is, if you are going to use for…in loops and prototype.js you will need to add an extra IF statements to filter out the results. I want to make it quite clear that this is not an issue with Prototype.js but more an issue with the JavaScript language.

Cameron Web Development ,

Getting Apache to run on port 80 on Windows 7

January 25th, 2009

Update

This solution is no longer necessary. It turns out a service called BranchCache is the culprit. Disabling this service stops Windows from listening on port 80 thus allowing you to run a web server. The description for BranchCache under services.exe is ‘This service caches network content from peers on the local subnet.’

Thanks to a fellow beta tester for the latest resolution.

I’m currently beta testing the next version of Windows, Windows 7 and came across a strange issue while trying to get Apache to install and run using the default port, 80.

Running the command ‘netstat -ano’ from the command line revealed
that port 80 is being used by PID 4.

Looking up PID 4 using Power Shell and then Task Manager revealed
that PID 4 is the NT Kernel!

So Windows 7 by default appears  to be using port 80.

After a bit of hunting around the Internet and doing some research of my own I found that the service http.sys was the culprit and all I needed to do was disable it but I could not find this service listed in the Services control panel applet.

So what’s the solution?

You have to disable the http.sys service manually via the registry:

1) Launch RegEdit:

2) Go to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP

3) Add a new DWORD (32-bit) value

4) Name it ‘NoRun’ not including the quotes

5) Double click the new property

6) In the Value data field type ‘1′ not including quotes and click OK

7) Re-boot your computer

You should now find that Apache will start on port 80!

Cameron Windows 7 ,

My blog is back, again!

January 25th, 2009

I’m very sory if you were following my blog last year and noticed it disappeared. I had to move web servers and lost my database. But now I’m back for good.

I will shortly be adding back the posts from my previous blog using the power of archive.org. If you’ve not tried it, now is the time. Just enter any website address and view snapshots of the site from previous years. It’s great, I recommened looking at Google and Microsoft 10 years ago!

Anyway hope you can forgive the outage and enjoy my new blog.

Cameron Uncategorized