Jul 6 2012

StackOverflow Traffic

There is nothing more that I like than to received a comment to some post I wrote years ago on how it helped someone out. Like this, I’ve come to know that small chunks of code I’ve freely made available are used in production at a variety of sites. It is my hope that the tutorials, examples, and code I write here is of help to others. Even though I like writing tutorials and code to help out my fellow developers, I’ve never answered or posted a question on StackOverflow. My technical blog is really a labor of love and I post around my busy schedule, I’ve never tried to do more than just write about the technology that I use. But even though I don’t use StackOverflow I recently found out from looking at my analytics that I receive a nice amount of visitors from the question and answer site.

StackOverflow Stats

StackOverflow Stats

It always surprises me which posts are the most visited. It’s always the one that you least expect. Either way, I’m always grateful that others have found them useful enough to share on sites like StackOverflow.


Jun 14 2012

Breakdown of Proposed Generic Top Level Domains

ICANN, the organization that regulates domain names, has allowed organizations and individuals to apply for new generic Top Level Domains (gTLD). A Top Level Domain (TLD) is the a domain extension such as .com or .org used by millions of websites. In addition to .com and .org there are country specific TLDs such as .co.uk, .fr, and .mx. ICANN has nearly 2,000 applications for new gTLDs. ICANN has released to the public gTLD application information such as the newly proposed domain extension and the applying company. For example, Google has applied for nearly 100 domain extensions including for .app, .youtube, .goog, .plus, and many more. Google clearly can afford the $185,000/application fee.

I downloaded the data, played around with it and generated some graphs to help me visualize the new land rush for domains. Please note that I discounted and removed a few gTLD applications for non-latin domains.

The first chart shows that nearly 50% of the new domain extension originated from North America. North American and Europe combine make up over 80% while African organization only applied for roughly 1% of proposed new domain extensions.

The following chart shows that a large number of the new proposed generic domain extension are under five characters long but there are a few that are up to eighteen characters in length.

The following graph shows the most popular proposed domain extensions. For example, thirteen different individuals or organizations applied for the .app TLD, eleven for .inc and .home, ten for .art, etc. This chart shows only domains with five or more applications.

As previously noted, Google applied for nearly 100 domain extensions… 98 to be exact under Charleston Road Registry Inc. Top Level Domain Holding Limited registered 68 gTLDs followed by Amazon with 65. Apple doesn’t appear in this chart because this graph shows application organizations with more than ten domain extension applications.

I also wanted to graph the number of applications per primary contact and found out that a single individual, Daniel Schindler, has filed for three hundred domain extensions. Looking at the data, each of the applications submitted by Mr. Schindler are for distinct legal entities.

So who is the real domain squatter? ICANN will be squatting on nearly $400 million because of the $185k/application fee. Another question is, how will a flood of new gTLDs affect the value of current domains? And perhaps most importantly, how will the private organizations use and restrict access to these domain extensions?


Jun 8 2012

JavaScript StackTrace With The console Object

Error handling and debugging had been made difficult in JavaScript because the lack of tools and the language itself. Unlike Java, that has a strong type and hierarchy of exception classes, JavaScript didn’t even have a direct approach to print the execution stack trace. For years I used a workaround to navigate around stack trace of a method call in JavaScript by using the Function arguments property. In JavaScript, all functions have an arguments property defined. The arguments property is available even if the function is defined with no explicit function parameters. The function arguments property behaves like an array and you can iterate through the argument parameters used to call the function but it also has a reference to the caller via the arguments.callee property. The arguments.callee property references the currently executing function itself, which has a caller property to that of the previous function call in the execution stack.

function basicFunction() {
   var isTrue = arguments.callee == basicFunction; // true
   var callingFunction = arguments.callee.caller; 
}

In the above code, the callingFunction variable holds a reference to the Function object that called the basicFunction.

The caller property returns a Function object or null, so you can chain these until you get to the root of the call stack. You can iterate through a call stack in JavaScript with code similar to the following.

function basicFuction() {
   var caller = arguments.callee.caller;
   while(caller != null) {
      console.log(caller);
      caller = caller.caller;
   }
}

Unfortunately, there is no clean way to get the function name out of the Function object returned by the caller property. This is made slightly more difficult because somethings functions don’t have names if they are created anonymously. If you print or log a Function object, it displays the function definition in its entirety.

Fortunately, the JavaScript console object provides a trace function that will log to the web console the JavaScript stack trace.

function basicFunction() {
   console.trace();
}

If the above function is invoked from an on click event, the whole JavaScript track trace from the on click to the basicFunction function is logged out in the web console. In addition to the function names, the web console in Safari, Chrome, and Firefox have a link to navigate to the exact location your web application where the functions were called.


Jun 4 2012

JavaScript Debugging With The console Object

In the early days of JavaScript there were few options for debugging large web applications. You could have used the multiple alert notifications or possibly even calling document.write to write messages into the document. Firebug changed web developers lives, and I think how we view JavaScript, by making it incredibly easy to debug HTML, CSS, and JavaScript. Since Firebug, most current versions of web browsers include powerful debugging tools. In addition to the debugging tools browsers have made available a JavaScript console object to help write debug statements. With console, there is no need to pop up alerts to inspect the state of an object. To write a log message intended for the console, just write the following JavaScript statement in the right place.

console.log("This is a log message");
console.log("Message one", "Message two", "Message three");

To open the console, you can find it in Safari by looking for the the Web Inspector, in Chrome it’s called Developer Tools, and in Firefox you’ll find it under the Tools menu as Web Console.

The console object has a lot of useful debugging messages for errors with different severity, such as log, debug, info, warn, and error.

console.info("I'm here.");
console.warn("Do I smell smoke?");
console.error("The roof, the roof, the roof is on fire.");

In addition to logging String messages, you can log whole JavaScript objects. It may be useful to inspect a complete object and it’s state. To write out the state of an object to the console use the dir method as in the following example.

console.dir({fname:"Bill", lname:"Gates"});
console.dir(document.getElementById('SomeElementId'));

In Chrome and Safari, you can also use dirxml to display the a HTML element object in the console as HTML. In my version of Firefox, this method did not work.

console.dirxml(document.getElementById('SomeElementId'));

You can also group related log messages, no matter their severity. To group console messages surround them with a group and groupEnd. You can even nest groups inside of groups.

console.group("Server update");
console.log("calling server...");
// ... any number of console log messages.
console.groupEnd();

You can also test the performance of your JavaScript code with time and timeEnd. Both of these methods accept a String label and it needs it needs to be the same value for both methods.

console.time("Process Data");
// ... some time consuming code
console.timeEnd("Process Data");

When the timeEnd method is executed it will generate a message in the log console with the amount of time it took to run the code between the time and timeEnd method.

Chrome Developer Tools Web Console

Chrome Developer Tools Web Console


Mar 20 2012

Remove Invalid Ruby Gem Source

I was trying to install a Ruby gem and it keep failing. I keep getting the following error when installing a gem.

ERROR: http://gems.datamapper.org does not appear to be a repository
ERROR: could not find gem thin locally or in a repository

Because of the above error I couldn’t install a gem or even update my gem system.

I certainly don’t remember ever adding gems.datamapper.org as a gem source repository but now it is causing errors in my system. You can list all of your current gem source repositories by entering the following from your command prompt.

gem source

You may see a few gem sources possibly including repositories from rubyforge.org, rubyonrails.org, and github.com. In addition to these gems source, the problematic gems.datamapper.org was also listed in my system.

To remove the problematic source, gems.datamapper.org, enter the following command from the command prompt.

gem source -r http://gems.datamapper.org


Feb 13 2012

iOS Missing Feature: Multiple Device App Management

I have over 100 iOS apps in three different devices, an iPod running running iOS 4.2, and an iPhone and iPad on iOS 5. As much as possible, I always sync all devices to my laptop so that they all have the latest updates. I know that since iOS 5, apps and songs purchased from iTunes on one device will automatically sync to other devices. That said I still find that I have sync for other reasons, to transfer photos to iPhoto and sync a large number of podcasts I listen to. And perhaps, most importantly, I’ve sync to charge my device. One issue, definitely first world problem, I have with having multiple iOS devices is managing all the apps in the different devices. If I delete on app from the iPad, it doesn’t delete it from the iPhone. If I delete it from the iTunes on my laptop and I sync with a device that contains that app, it will copy it back to iTunes.

Another big issue is that you have to configure your app pages and folders on each device. If you spend an hour organizing your apps into folders and pages in one device you have to re-do it all over again on the second device. What ends up happening is that you’ll have two devices with the same apps in different pages and folders.

What I am missing from my mobile experience is the ability to sync, not only the apps and content of apps, but the meta-data about how I organize apps between iOS devices. I want to have the choice to clone how one iOS device organizes and layouts the apps to other devices. I would also like the ability to have different app layout settings, such as have the iOS device automatically put applications into folders based on the app category or my usage of the app. And of course, I would like to have a way to delete an app from one device and have it disappear from all other devices.