* BlackBerry JavaScript Oddities
Posted on July 18th, 2010 by Dave Johnson. Filed under Uncategorized.
I have just discovered that the Element object in the BlackBerry browser (4.6+) supports the prototype object on some objects but not others. In particular the Element object supports it like this:
1 2 3 | Element.prototype.addEventListener = function() { alert('foo'); }; |
but the following does not work on the Document object:
1 2 3 | Document.prototype.addEventListener = function() { alert('bar'); }; |
What does work on the Document is overriding instance method like this:
1 2 3 | document.addEventListener = function() { alert('foobar'); }; |
Strange but true!
If you have any other BlackBerry tidbits please let me know since these old versions of BlackBerry browser are going to be the IE6 of the the mobile web.
* JavaScript Event Merging
Posted on July 14th, 2010 by Dave Johnson. Filed under JavaScript.
In a recent project I finally decided to write something to help with JavaScript event merging. There are often cases in JavaScript where you want some code to run but only after certain events have fired or other code run - in my case I wanted to execute a JavaScript function only after two different bits of code had executed. The most common use case for event merging I have come across has got to be on page load / DOM ready where you may need several conditions to be true before executing some JavaScript code.
Event merging generally helps you to better separate your concerns and not have unwieldy if conditions strewn throughout your code checking if certain condi.
If you have a basic JavaScript object called the “Subject” that has subscribe, subscribeOnce (events that auto-unsubscribe themselves after being fired the first time), and notify methods on them. You can use the following merge function to have all subscribed code executed only after each of the events passed to the merge function are fired. In this case I have explicitly used the subscribeOnce method on the event.
1 2 3 4 5 6 7 8 9 10 11 | function merge(handler, events) { var i = events.length; var f = function() { if (!(--i)) handler(); } for (var j=0; j<i; j++) { var e = events[j]; (!e.fired?e.subscribeOnce(f):i--); } if (!i) handler(); } |
When the merge function is called it iterates over all the events in the event array argument and checks if that event has already been fired or not by checking the “fired” property on the event - note that this makes it so that it doesn’t matter if merge is called before or after the events have fired. If the event has not been fired yet then a handler is attached using subscribeOnce where the handler checks a counter indicating how many of the events have been fired, once the counter hits 0 then the final handler for the merged events is called.
I have put up an entire event merging code on Github here.
* Smart Grid Utilities
Posted on June 22nd, 2010 by Dave Johnson. Filed under smart grid.
The “smart grid” is a pretty popular term these days is used to describe a new generation of electricity distribution network or grid where electricity usage at by the end user is tracked in real time. Today, tracking of electricity is done by prediction until the utility physically sends a person to the consumers location who then reads the value on an electricity meter. This new real time tracking of usage also means that the consumer can not only see their usage at any given time, but they can also see the price of electricity at that time allowing them to make decisions to try and save money - generally that means using electricity at night when rates are lowest.
If there is one thing that is clear, it is that the smart grid is going to be built on Internet standards like TCP/IP, the only question is what medium it will use. It might be WiFi, mesh networks, power line communication, cell networks, radio, or just plain old broadband.
The interesting part is that however the data gets from your house or business to the utility, it will have to be over a TCP/IP network that could conceivably have enough bandwidth to also provide you with services ranging from Internet to phone to television - as many telecommunication companies do today.
With enough bandwidth a smart grid utility could provide ALL of your utilities.
Companies like Google are certainly ready to be the provider of all the software a utility might need on top of an Internet connection to be your single utility provider. With Chrome OS or Android as the nervous system of a smart house to Android on your mobile phone, TV, Voice and PowerMeter. These pieces of software could even come from various providers like Skype or Microsoft but certainly using a battle hardened, open source, developer friendly operating system like Android at the core makes sense. Beyond that they should also be taking advantage of the increasingly powerful smartphones like the Android, iPhone and Blackberry and using them as the user interface to all of their smart systems.
In the past the stringent security and reliability requirements placed on utilities probably forced them to write their own software preferring security through obscurity rather than using open source software that probably didn’t even exist. Today is different though and there are many open source software projects that can likely stand up to their requirements.
If utilities were as smart as they hope their grid will be, they would be ensuring that their smart grid offering gives them the ability to offer other value added services to their customers just as other communications companies have either moved from providing broadband to providing voice services or vice versa.
* PhoneGap Desktop
Posted on April 20th, 2010 by Dave Johnson. Filed under phonegap.
So if PhoneGap was running on the desktop, what would you call it? Well I have not come up with a good name yet but after a few nights of hacking we threw together a version of PhoneGap for Mac OS http://github.com/shazron/phonegap-mac and a version for Windows http://github.com/davejohnson/phonegap-windows.
@shazron has implemented the sound API on the Mac version and I did Geolocation on the Windows version using a simple GeoIP lookup.
Check it out, write some code, and let us know what you think!
For the Windows version I have used the awesome WebKit .NET project written by Peter Nelson. If you use the Visual Studio 2008 solution file, you will have to download the source or binary versions of WebKit .NET and setup the references correctly. I have so far used the 0.3 release of WebKit .NET. It is pretty cool being able to write a native Windows app (or Mac OS) in Canvas using all free and open source code
One other caveat on the Windows side is that you might need to install some Visual Studio C++ redistributables for building it … check the WebKit .NET forum on SourceForge for all the details.
* Crockford Facts
Posted on March 18th, 2010 by Dave Johnson. Filed under JavaScript.
Everything that you want to know (or not) about Douglas Crockford.
Or following things live on Twitter.
I contributed a few of my own like:
“Crockford doesn’t throw errors, he roundhouse kicks them.”
Andrew Lunny also directed me to this site with some Resig facts … hilarity!
* QUnit Server
Posted on March 1st, 2010 by Dave Johnson. Filed under Components, JavaScript, Testing.
QUnit is a great little JavaScript test framework written by none other than John Resig of jQuery fame.
I love how easy it is to write tests, especially asynchronous ones, with QUnit and so was quick to start using it for my JavaScript tests.
The one thing that I found it lacked was support for continuous integration products like Hudson, CruiseControl or Continuum. So I figured that I would change that.
For a long time I have been using JsUnit along with JsUnit Server to merge in client side JavaScript test results with a server side test integration workflow. Essentially, JsUnit Server is a Jetty server and JsUnit posts back a form with test results to that server, which logs the results to standard JUnit formatted test results files. Those files can then be read by most continuous integration products and included in their reporting.
What I decided to do was hack QUnit so that it too could submit test results back to the JsUnit Server in the same format that JsUnit submits results and could therefore continue using the same JsUnit Server workflow and simply change the client JavaScript test framework to QUnit. It worked like a charm!
I wrote a couple of simple function that in the background dynamically create an HTML form in the QUnit test page and add the results to the form as each test is run. When the tests are complete the page submits back to the JsUnit Server and the test results are logged as they were when I was using JsUnit.
It is some pretty simple changes but does make using QUnit that much better, especially if you were hesitant to switch just because the continuous integration support was not there for QUnit.
* Require RubyGems
Posted on February 19th, 2010 by Dave Johnson. Filed under ruby.
I have never really written much ruby outside of a Rails app and so when I wanted to write a short script for a cron job.
I kept getting an error like:
‘require’: no such file to load — some_gem (LoadError)
In the end it was all because I had forgotten to first require rubygems!
It was a hard thing to find an answer to from The Google.
* HTML 5 and sessionStorage
Posted on February 19th, 2010 by Dave Johnson. Filed under JavaScript, quirks.
We came across a strange bug today that was being caused by our recent addition of sessionStorage to our application.
The Mozilla Developer Center says this about sessionStorage:
This is a global object (
sessionStorage) that maintains a storage area that’s available for the duration of the page session. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated.
Emphasis mine.
What we found was that of the three different browsers that currently “support” sessionStorage, there are three different implementations. Go figure.
I looked at a few different ways of opening new windows or tabs and those included anchor tags with target values of “” and “_blank”, window.open() JavaScript calls with different targets, and context menu open in new window or tab.
Internet Explorer 8 is furthest from the spec, as one might expect. No matter how you opened a new window from the page, the sessionStorage is preserved in the new window.
Firefox is only slightly better in that it does not preserve the sessionStorage in new windows when the new window is created by choosing open in new window / tab from the context menu on an anchor.
Safari is more or less like Firefox except that it does not preserve the sessionStorage when the target on an anchor is “_blank”.
In short, if you are expecting that sessionStorage is tied to a single browser window then think again.
* Work
Posted on January 11th, 2010 by Dave Johnson. Filed under phonegap.
Crap it has been busy at work the past few months!
More to come soon though since I am working on a few small JavaScript libraries and two services that I will be releasing soon!
There has of course also been a tonne of amazing work being done on PhoneGap (tests, Palm, Nokia, simulator) - though not by me so much
Check out the latest at GitHub http://github.com/phonegap
* Managers and Technical Debt
Posted on September 2nd, 2009 by Dave Johnson. Filed under Business.
Managers love technical debt. It helps them to make it seem like they are doing a better job than they are. They can do this in a few ways.
First, by skipping tests and taking on other types of technical debt during development they come slightly closer to meeting tight timelines and releasing software that is not as good as it could have been, but good enough.
Second, when there are bugs found in the software the manager can blame the developers who were previously told to omit things like tests in an effort to get the software out sooner. Not only do the developers take the blame, but they are also forced to fix the bugs, often by working long hours outside of regular business.
The end result is that the software is closer to the quality it should have been in the first place, and the developers have done it in record time because they had to work evenings and weekends. And the manager, has not only released the software on time but he has also taken the credit for the heroic bug fixing effort.
That leaves the developers paying off the technical debt and looking for a new job where, hopefully, it won’t happen again.
Recent Posts
- BlackBerry JavaScript Oddities
- JavaScript Event Merging
- Smart Grid Utilities
- PhoneGap Desktop
- Crockford Facts
Archives
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- January 2010
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
