Search
Feeds

Monetize
Tuesday
26Jan2010

The Importance of Rumors

Over the past few months, as Apple Tablet rumors and speculation have heated to a feverish pitch, I've noticed two trends that really caught my eye, first during the coverage of CES. The first trend is a combination of many factors that have caused an interesting response from people who are excited about the potential for a tablet computer.

I've observed, in listening to interviews and even in my own excitement about the devices potential, that many people have risen the idea of a tablet computer from Apple into an almost god-like symbol that solves all of their computing problems. This is, more or less (probably more), a result of the track record Apple has had in recent history regarding the success of it's products, putting Apple devices on a plateau of excellence that few companies have succeeded in achieving. People expect Apple products to fill a gap in their life in an elegant, efficient, and beautiful way.

I don't claim to be any exception from this rule, I have my visions of gradeur about the device as well. I personally feel that one aspect of the device that some people have not taken into consideration is one of the key demographics that Apple is most popular with: college students. The speculation that Apple's tablet will attack the Ebook market, much as it did the music market, brings up the potential for the Apple tablet to become a successor for college students who purchase Macbooks. Think of having all of your textbooks and notes on an elegant and light device... I'd buy that for a dollar.

And this is exactly what I'm talking about. As I am currently a student (and gadget whore, there, I said it...) with a desire to streamline the process of attending school and managing all of the information contained therein, I've imbued the tablet with all of the traits that I see as being useful to me. I've seen countless people from all interests do the same thing. Obviously we can't expect it to solve everyones problems. Hell, to be completely honest, we don't even know what it is but I think that this explosion of theoretical thinking regarding what problems this device can solve for people is ultimately a very important thing, which brings me to my second observation.

Anyone who followed the coverage at CES will have certainly noticed that many device makers were preempting Apple's tablet release. Some were even brazen enough to name their devices after a few of its rumored names. While many of the devices will fade into the ether without ever hitting the shelves, I do honestly believe that the interest people have taken in crafting devices in their minds-eye that will solve whatever problems they have will ultimately drive innovation. We've already seen a slew of innovative devices that have tried to solve each of those problems, such as the Lenovo U1 and the plethora of third-party Ebook readers, each with their own unique take on the direction of the device.

All things considered, I find it particularly interesting that when rumors of an anticipated device begin to fly, especially with the fervor that accompanies any Apple announcement, average people begin to dream up devices that solve their problems and ultimately begin to drive the industry in a new direction by thinking differently. Even if Apple doesn't announce a tablet device, a mark has been made that there is an opportunity for someone to produce a device that solves these problems.

Tuesday
12Jan2010

Google <3 The Internet

If you haven't read this recent post on the Official Google Blog, I recommend you give it a once-over. Wait, no, give it a twice-over. Really let it sink in.

We all have that fear in the back of our mind about trusting Google with so much of our information but so far they've done a great job of sticking to their "do no evil" motto. I must say though, this recent move by Google has made me at least slightly more hopeful that their motto is sincere and that they will stick to it as they continue to change the web and our lives.

I have no statistics about the type of penetration Google has in the Chinese market since it appears that they already censor Google Apps like Gmail and Google Docs but what kind of impact do you think pulling out of China would have? Are we about to see firsthand the power of information used to strong-arm a government into complying with a policy of openness? I seriously doubt the last part, but it will be interesting to see how the Chinese government and it's people react to this momentous change.

Saturday
14Nov2009

Haikus for Our UPS Man

In order to persuade our UPS man to leave a package I was expecting, Teya wrote him a few haikus. In the end he left the package and took the haikus.

Sunday
08Nov2009

BSOD Karaoke

Follow the bouncy... erm... memory address?

 

Thursday
05Nov2009

Elegantly Handling AJAX Errors in ASP.NET MVC using jQuery

One issue I've always struggled with when using AJAX is how to handle server side errors. I would usually wind up writing a bunch of code that would return some type of response code to indicate what happened on the server. As you can imagine this is incredibly tedious, messy, and horrific to maintain. Tonight as I was working on a project I came up with an elegant way of handling such scenarios that I thought I would share.

To begin, I always inherit all of my controllers from a custom base controller class. Within that base controller I added a method and event, shown below:

protected JsonResult AJAXError(string message)
{
    if (String.IsNullOrEmpty(message))
        message = "Oops! Something went wrong while processing your request.";

    Response.StatusCode = 500;

    return Json(new { ErrorMessage = message });
}

protected override void OnException(ExceptionContext filterContext)
{
    if (Request.IsAjaxRequest())
    {
        filterContext.Result            = AJAXError(filterContext.Exception.Message);
        filterContext.ExceptionHandled  = true;
    }

    base.OnException(filterContext);
}

The OnException event catches any exceptions that are thrown during the execution of controller actions. Within this event, we first check to see if the exception occurred during an AJAX request. If so, we set the result to the return value of our AJAXError method. The AJAXError method only does two things, it sets the StatusCode to 500 (Internal Error) so that the AJAX request shows itself to be an error and returns a JSON object with an ErrorMessage property that contains the current error.

Something else to keep in mind is that often times when a site is public, you won't want all of the details of the error being published to the user. This opens up a potential security risk if critical information is leaked out via errors. In my code (not shown above), I account for checking to see if the site is in production use or in debug and if so change the error message to a default error. This will prevent unwanted information from leaking out.

Onward!

The second part of the solution comes with the help of jQuery's global ajaxError event. Within a client-side javascript include, I have the following code:

$(document).ready(function() {

    $(document).ajaxError(function(event, XMLHttpRequest, ajaxOptions, thrownError) {
        var result = $.secureEvalJSON(XMLHttpRequest.responseText);
        ShowDialog(result.ErrorMessage, "Oops! There was an error.");
    });

});

jQuery provides the ajaxError event as a means to catch any errors that are fired from all AJAX requests on a page. Remember the JSON object we return from the server-side AJAXError method? It winds up in the XMLHttpRequest.responseText property as a JSON string. To make things easier, we need to convert that JSON string to a JSON object. Some people will suggest using the eval method to do this but I would urge strongly against that. Doing this could potentially allow an attacker to execute client-side code.

After a bit of research, I opted to use the jquery-json plugin (found here) to handle the conversion. The jquery-json library provides us with the $.secureEvalJSON method, allowing us to translate that JSON string into a JSON object.

Calling result.ErrorMessage will now give you the message that was set on the server side, allowing you to alert the user about the issue. The ShowDialog function above is simply a method I put together to display a jQuery Dialog Box rather than a plain alert.

I'm pretty happy with this solution because not only does it catch any unexpected exceptions on the server-side, but you can use the AJAXError method to return an error when doing data validation. For example, here is some code from one of my actions:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult UpdateUserDetails(FormCollection collection)
    {
        Contract.Requires(!String.IsNullOrEmpty(collection["username"]));

        var profile                 = this.Users.GetUserProfile(collection["username"]);

        if (profile == null)
            return AJAXError("There was an issue updating user details. The users profile could not be found.");

        /* Do some stuff... */

        profile.Save();

        return new EmptyResult();
    }

If the users profile can not be found, we just return an AJAXError with the error details and that gets reflected on the client-side automagically.