Tuesday, October 18, 2011

Windows Phone 7.5 Mango Review: Search

In Windows Phone 7.5, there are a plethora of new features that are integrated into search. Previously, it only allows you to basically go to Bing! and enter your text or keyword into the search box. Now, the search is deeply integrated and can seamlessly jump into apps if necessary. Not only that, there are also Music Search, Bing Vision, and Voice (Search).

Voice (Search)
With the Voice update in Mango, now you can hold the Home button and say stuff like "Call John" or "Text Jack" or "Open Maps". Along with all that commands, it also allows you to do searches with Voice - so you can say "Find Pizza".

This is very helpful for searching during driving. I have used this feature several times and it works pretty well. Plus, it's easy to enable, just hold the "Home" button and speak. Also, if you receive an SMS, you can say "Reply" or "Read" to reply or read respectively - and then dictate your message to the phone.

Android has had this feature for a while, but the Froyo, Gingerbread, and Honeycomb versions that I have used (HTC G2, Samsung Galaxy S, Samsung Galaxy Tab) were not accurate and cannot recognize non-western names. Let's see whether Ice Cream Sandwich will bring improvement on this. I was expecting Mango to be the same way - but I was surprised that it actually recognizes most of my contacts, including the ones with non-western names. It is not as impressive as Siri in iOS5 (yet), but it's not bad, not bad at all.

Music Search
Music Search is basically like running Shazam, but much better. There is no limit on searches, it also finds songs better by displaying artist, song title, and album, but also shows you where or how to play or buy it from the Marketplace.

Previously I used Shazam - which works OK, but the free version only provides limited functionality and music searches. The Mango Music Search however, is very simple to use and unlimited in usage. I also found out that it is actually more accurate (at least in my experience). After searching for music and getting a result, I can go to the Marketplace - and then either purchase & download or play the song. Since I have a Zune subscription, this works awesomely. The integration with the OS itself is also worth it - I do not have to open an app nor open the Marketplace separately.
Shazam is good, but the Music Search is better.

Bing Vision
Bing Vision allows you to search using the phone camera. It can recognize text, Tag code, UPC code, QR code, etc and display the product information at an instant. It also can search based on book cover, CD/DVD covers, and game covers. Initially I thought this is just a novelty or to just making search easier. But, not only it does make search easier (e.g. capture the cover of the book vs typing the title), but it can also capture text (like document scanning).

Search Result
Search result is now getting smarter. When I searched for "pizza", it automatically displayed the result in the "local" pivot area. I can swipe and go to the "web" area if I want, but the "local" area makes much more sense. Then if I select a search result from result, Mango brought me to the pivot card for the result (which is most likely a pizza restaurant) - which is filled with the contact information, hours, neighborhood, etc. I can swipe and see all the reviews aggregated for the restaurant. Another swipe got me to the "apps" pivot area - which enables me to launch related apps such as Foursquare or Twitter etc via App Connect.

When I searched for "moneyball", it displayed the result in the "web" area, with local showing cinemas on the top. I can that one of those if I want to watch the movie at the local theater which then - just like the restaurant - shows its own hub, with "about", "showtimes", and "apps".

App Connect
App Connect is super useful. So basically instead of launching an app from the Start or Home screen, I can seamlessly launch relevant apps from connected apps/area. One of those connected area is the search result screen. So for example, if I want to watch the trailer for "Moneyball", after searching it on Bing, I can just go to the "apps" pivot area and tap on "Flixster" or "IMDB", which will launch directly to the the Moneyball page within the respective app. Previously before Mango - or on iOS or Android - I will have to go to "Home" and open up "Flixster" and navigate to the "Moneyball" page.

There is a video about App Connect in the Bing blog, you can watch it here.

So overall the search experience has tremendously improved. I am using search more and more on my phone now and looking for further future improvement in this area in the next Tango release.

My other WP Mango Reviews:
Windows Phone 7.5 Mango Review: Update Process
Windows Phone 7.5 Mango Review: Email & Calendar
Windows Phone 7.5 Mango Review: People & Me
-- read more and comment ...

Sunday, October 2, 2011

Windows Phone 7.5 Mango Review: Email & Calendar

This is the 3rd part of my Windows Phone 7.5 Mango reviews - which talks about Email. See previous reviews here and here. In the initial release of Windows Phone, email was already quite good. It syncs seamlessly with my Exchange account, Hotmail, GMail, etc. Each inbox will create a different "email app" and I can pin each one of those to the Home screen.

I can also be selective about how to sync the folders, how long should it went back to sync, etc. The interface was a delight to use - the typography was good, text and formatting are pleasing, attachment are supported, and the notifications of new emails on the Live Tiles are purely awesome.

Overall, it was a good and nice experience. So what did Mango bring to the table?

Email
Mango brought quite robust improvements for Email. First of all, email conversation is now threaded. This is a must have feature nowadays. The top email shows a bit summary of how many emails are in the thread and how many are unread. You can open/close the thread by tapping on the top email. For selecting the whole thread, you can select the top email (just like before) by tapping on the left of the email - or you can select individual emails within the thread.

Another new feature is now there is an option for combined/linked inbox. So instead of having separate "email app" for Outlook/Exchange, Hotmail and YahooMail and GMail etc, now you can linked them anyway you want. For me, I separate my work email (Exchange) and my personal emails (Hotmail & GMail - into a linked inbox). So now, instead of having 3 Live Tiles on my Start/Home screen, I have 2 tiles. The linked inbox has a separate icon and you can name it what ever you want.

When composing a new email from a linked inbox, it will ask you which email account to use for sending the email. Another cool feature here is that now you can email to "Group". So instead of typing the recipients one by one, you can just email to "Family" group and Mango understands that and will insert the email for the people in the group. Very neat and certainly something that I will use a lot - since I do a lot of group emails (such as to family/church groups/work etc).

Calendar
The Calendar has a subtle but awesome feature upgrades and additions, mainly multi-calendar support, Facebook calendar integration, and sync with Tasks/To-Do in Exchange. Multi- calendar support means you can view events from other calendars within the same calendar, filter them, color coded, etc. It also auto-sync with your Windows Live calendars, which include US Holiday calendar. When creating an event, you can specify which calendar the new event belongs and syncs to. If you are integrating your Facebook account, this will then include your Facebook events.

Mango also natively allows To-Do list or Task list, and if you put a due date, it will automatically put it in the calendar. If you are using Exchange, then there is an option to sync it with your Exchange Tasks.

There is also a new set of APIs that allows apps that take advantage of the built-in gyro, accelerometer, etc. to be able to communicate with the calendar.

Overall for Emails and Calendar, I was happy before - but now I am happier. There are several things that I found that I hope Microsoft will address or add in the future for Emails and Calendar, but the current Mango features really do provide the essence of what I need.

My other WP Mango Reviews:
Windows Phone 7.5 Mango Review: Update Process
Windows Phone 7.5 Mango Review: People & Me
Windows Phone 7.5 Mango Review: Search
-- read more and comment ...

Thursday, September 29, 2011

Windows Phone 7.5 Mango Review: People & Me

The "Me" tile was useless to me before Mango update. It had my picture and the word "Me". Clicking on it brought me to my personal information page. I had it for the first day after I bought the phone, but removed the tile the next day and never pinned it again until several days ago, after the Mango update.

The old "People" tile was basically like "Contacts", it stores all my contacts from Exchange/Outlook, Windows Live, GMail, Facebook, and other services that I included. The "What's New" area displayed all Facebook updates. So mainly, it does the basic stuff - and for me, since I don't usually connect my Facebook to my phone, my "What's New" is always empty, I also do not want to clutter my Contacts with my Facebook "friends", since there was no way to filter my Contacts before Mango.

So what does Mango bring to "Me" and "People" hub? A lot.

"Me" Tile
Mango brought Twitter & Windows Live chat integration. So in the "Me" tile, I can change my chat status ("offline", "online", "busy", etc) - without opening an App. One of the most important feature in the "Me" tile now is "post a message" - which is a "status update" for either Twitter or Live chat. Since I tweet a lot, this then becomes one of the most frequently used feature for me - again, without opening any app. It also allows me to "check in" - a Facebook check-in integration (I wish it was a Foursquare one). From it you can choose a location or add new ones, and then add comments.

The Live Tile itself now displays how many new notifications I have. These notifications are derived from mentions in Twitter, Live chat from people, Facebook posts on your wall/conversations and mentions. This is truly adhere to the "Glance & Go" concepts, where I can glance and see my notifications in one place, inside the "Me" tile - without the hassle of opening up each individual apps to see what's going on.

"What's New" now is filled with my Tweets or twitter posts, my Facebook posts, and Windows Live posts as well. This becomes like the "sent" folder of some kind. I don't find this that useful, although I can see some people may have more use for it.

"People" Hub
Now, "People" hub is much more than "Contacts". First of all, with the integration of Twitter, the Live Tile for "People" also displays avatars now. Same thing with people's Live Tile - it alternately display their avatar, Facebook photos, and their local avatar. Not only that the tile now also displays their latest status updates from Twitter or Facebook or Windows Live. It isn't just the place you look for a phone number or email, but much more - where you can find out what's going on with your friends via social network. This is pretty neat - I can view the status updates of the people I consider important (since I put them on my Home) without going into their "People" view or opening up an app! Truly in line with the "glance & go" motto!

Windows Phone integrates and try to sync your contacts from all the services that you allow it to connect - for me this is Twitter, GMail, Windows Live, and Exchange. If somehow it does not find the connection between accounts, you can link them yourself and integrate the people's card into one. In my case, out of a couple hundred contacts, I only have to do this for less than a dozen contacts, and Windows Phone has done the rest - IMPRESSIVE! But that feature is pre-existing from pre-Mango - the new feature in this case is now I can filter my contacts and only display selective contact source in the "People" hub. This is a major feature for me - as I don't want my "not-in-Exchange" Twitter and Facebook friends to show up in my "People" hub. But they are still searchable and link-able! Yeay - so they are not cluttering my "People" hub, but they are still there and I can still interact with them through my phone. This sounds simple, but in practice this is truly brilliant and score an extra user-friendliness point from me.

The "People" hub has its own "What's New", which shows status updates and posts from the people. But now, you can filter them, just like contacts. You can choose to show all, or just twitter, or just Windows Live, Facebook, or any combination thereof.

In Mango, you can also create "Groups" of people or contacts (like "family" or "soccer guys" or "co-workers" etc). These "groups" show up in the "People" hub, and you can send emails, SMS to the group at once. This is very nice and very intuitive - the group name shows up during the auto-complete when you are filling in the recipient list for your email or SMS. The "Group" hub also has its own Live Tiles for each members and has a "What's New" screen, which shows status updates and posts from the people in the group. Just like regular contact, you can also pin the group to the Home screen - which creates its own Live Tile. I feel that this is pretty well thought out and designed - and since mostly I interact with people in groups, this feature is a killer for me, which really is easy to setup and gives a uber-nice experience and a delight to use.

Inside a particular contact panorama page, now there is a "history" pivot page. This gives you a running historical list of your interactions with this contact - from emails, phones, and SMS. You can filter it to display only "yesterday" or "last week", etc.

There you go - is it perfect? No. I have my wish list:
1. The notification list in the Me tile also includes SMS and phones.
2. History in People should include my Twitter & Facebook interaction with the person.
3. Foursquare integration for check-ins.
4. Twitter multiple accounts support.

I would say in closing for this part of the review is that the updates to the "Me" and "People" hub are impressive. This makes using a Windows Phone such a joy, even without installing any apps. The concept of "glance & go" is brilliant, so I can spend my time not in opening & closing apps, but still able to take care what or who I consider important quickly.

My other WP Mango Reviews:
Windows Phone 7.5 Mango Review: Update Process
Windows Phone 7.5 Mango Review: Email & Calendar
Windows Phone 7.5 Mango Review: Search
-- read more and comment ...

Wednesday, September 28, 2011

Windows Phone 7.5 Mango Review: Update Process

Windows Phone update, codename Mango (version 7.5) just got released on Tuesday, September 27th 2011 - it was highly anticipated and showcased repeatedly by Microsoft via numerous medias. With 500 or so new features, the Mango update is the push to get WP platform to be on the same competitive level as iPhone and Android. So finally it's here and I have installed my update and this is my review for the update and I will make this a series of reviews (instead of combining into a single bog post), starting with the update process itself.

UPDATE PROCESS: AWESOME
I was expecting it will be trickling slowly in US via carriers (like NoDo update) - mine would have been updated within 4-5 weeks after that date. But, it turns out that Microsoft really went above and beyond in making sure that the release process is unlike the NoDo update - I got my update right on that day and it seemed that everyone else was too. Overall the update process was smooth, although it was still via Zune instead of OTA.

Not only this is awesome compared to NoDo, but it is also awesome compared to Android updates. My HTC G2 just got updated to Gingerbread within the last 2 months and the Ice cream Sandwich update is going to be released within 2-3 months - so the lag is quite substantial.

All my apps and settings and data are all intact, and in fact the update process actually make a backup of my phone before executing the update, so in the case the update process fails or interrupted, it can restore the phone to the previous version. Once the update ran, all my apps that have not been updated to Mango were all working and everything is preserved. I need to no new device to experience the upgrade, my HTC HD7 runs just as smooth and awesome as before. The only thing that I will not be able to do with my HD7 is video-chat, since my phone does not have a front-facing camera.

This data and setting preservation is actually much better compared to the update process for iPhone. Going from iOS 3 to iOS 4 was a painful process, losing data and settings here and there. Most of the time, Apple requires you to get a new device to experience fully the new iOS functionality and performance.

For some of you who are still waiting, here is a trick you can use to force an update via Zune - check it out here.

My other WP Mango Reviews:
Windows Phone 7.5 Mango Review: People & Me
Windows Phone 7.5 Mango Review: Email & Calendar
Windows Phone 7.5 Mango Review: Search
-- read more and comment ...

Sunday, July 10, 2011

Samsung Galaxy Tab (10.1 Honeycomb) Experience

I got my Galaxy Tab as a gift from attending Google I/O conference back in May 2011. I have been using it pretty much daily, brought it along on a family vacation with my family for a week - and my wife and son also have been using it to check emails, play games, browse around, etc.

When the Tab was given to us by Google, it had Honeycomb 3.0 on it - since then it has been upgraded to Honeycomb 3.1. I won't bother you with detailed specs - you can see it here, but I will write about my personal experience with it from the last 2 months.

-- read more and comment ...

Sunday, June 19, 2011

Using Dapper.NET to Boost DAL Performance

Lately, my focus has been to optimize and increase the performance of our web-application. This, of course, includes load time and speed - among other things. There are a lot of performance enhancements that we can do to speed up our load time, from the UI stack (javascript loading, CDN, minimization, etc), DB stack (indexing, query caching, stored procs, etc), application/biz layer stack (algorithm optimizations, data storage, caching, etc).

Now, our web-app is using Linq-to-SQL as our DAL and since a year ago, we have been doing several things to speed up our DAL - by using compiled queries, creating stored procs, views, etc. One of the tools or library that I have been using to boost DAL performance is Dapper.NET.

-- read more and comment ...

Monday, May 23, 2011

Web Fonts - Why Haven't I Heard About This Before?

Most of the web only uses selective number of fonts, such as: Arial, Verdana, Sans, Times New Romans. But, what if we want to display certain text with certain fonts other than those - to convey some emotion maybe, or to portray certain values, etc? Are we stuck with those selective fonts?

It's true we can make the text to be bold, underlined, italics, etc. But I want to use "waiting for the sunrise" as my font type instead of "Verdana"! This is not easy to achieve because of several reasons:

  1. We are putting stuff on the web, so if the machine where the browser is running has the font that we want, it will display it. What if it doesn't? Then it will revert to the "default" font. 
  2. All machines or computers have those basic selective fonts - that is why people are mostly sticking with them, so they can be sure that whatever they put on the web will be displayed as intended on the browser.
  3. So far people have been working around this by using images - so if I want a menu or a logo with some font type that is not among the standard, I can make it an image using my image editor and include that in my web site as an asset/image file. This then ensures that it will preserve my intended design of the logo or menu or whatever. 
  4. But of course, making everything an image is a pain. It's hard to modify, it is not searchable by default, people cannot select/highlight from it, and it's bandwidth consuming. But we kinda stuck with it. 
Aren't there any other alternatives? 

-- read more and comment ...

Wednesday, May 18, 2011

Asking For Assistance While Minimizing Interruptions - How To Do It Well

It is always somewhat a dilemma when you have to interrupt somebody to ask him/her to help you. There is always a tension between the pressure or desire to solve your problems/issues/bugs and complete your task AND the realization that everybody has their own set of tasks to complete and you are just about to interrupt & tell them to drop what they are doing and focus their attention to help you.

Each person will have their own tendencies:

  • Some will just be too shy or reluctant to seek help and just keep banging their heads and hope miraculously or by luck that they will be able to resolve it. Therefore some issues can just linger in the bug list unresolved or taking longer than necessary to be closed.
  • Yet a different group of people will ask, discuss, and talk about their emerging problems/issues/bugs all the time with their colleague - and creating noise, constant interruptions, and annoying. 
We all know that the balance lies somewhere in between. We want to respect out friends/co-workers/colleague privacy, time, and work - while at the same time trying to find possible reasonable solutions or pointers in solving our issues.

This blog post is not about how long should you wait before asking question to others, but is about when you actually decided to ask somebody about your problem - and how to do it well.

One of the rule of thumb that I have heard and embrace is the 15 minutes rule - that if you encounter a problem and cannot solve it immediately, try to find some answers/pointers/hints on how to resolve it with all your might in approximately 15 minutes, and if you are still stuck, then get help from others. This works in theory but often what somebody does in that 15 minutes or so is just weird or not helpful at all. I have seen somebody basically just stare at their code up and down the screen and then declare a surrender. Or, hitting the same scenarios again and again, recompile, test with the same code again - which predictably yield the same errors/wrong results/problem as before. Some will Google their issue and read the search result and do nothing about what they read or just skim through the results.

To be able to ask for help well, I recommend doing the following:
  1. It is important to know and understand the error message you are getting - if any. You should not go to somebody equipped with "it does not work". It is really bad when somebody comes to you and just say "it's broken" and when you ask "What's the error?" that person replies "don't know".
  2. Do your own homework and reasonable research first. The 15 minutes above should be counted toward this. Trying possible scenarios and fixes, what works, what does not, noting them down, etc. Then communicate this to the person that you are seeking help from - so they don't have to waste their time in trying what you ave tried again. Bring screen shots, print out, examples, etc.
  3. When you are about to interrupt people, I recommend asking whether the person has some time to spare or whether they are free at the moment. I know some of my friends to away from their desks during lunches precisely because of this reason - so they are not interrupted during lunch. It's a good practice to respect people's time and space - and asking beforehand whether they can be interrupted or not goes a long way.
  4. If the problem is not that urgent, try email. Of course describing your problem in an email may take more time (screen shots, etc etc) and some times it is just not possible. But this also an alternative to get help from others without pressuring them to drop everything on their plate and solve yours.
  5. When people allow you to interrupt them, then describe your context, settings, cases, and ask your question decisively and quickly. It's confusing when someone just storm to your cubicle and say "It's broken, does not work at all!". OK - so what do you want me to do?? Here is an example: "Bob, I have been getting some errors in ELMAH about 'null reference error'. From the trace, it seems to be coming from ProfileEdit.ascx - which uses a custom editor template for a textbox for a string value. If I use a regular textbox, it works fine, only when using the custom template then the error shows up. The custom template uses same validation rules - which I am not familiar with - and the calculated null values come from that line. Do you have any ideas or hints that will help me?"
  6. At this point, we have to give them the freedom whether they want to respond now or later. Your colleague may say "Hm, let me look into it, I will let you know" - then we ought to thank him/her and leave, go back to our desk and do something else or do some more research. 
  7. Also try to ask for help during non-peak time. I like to ask help early in the day or right after lunch, before my co-worker get into their working zone mode. Since he/she is not in their zone yet, then it becomes less of an interruption for my co-worker(s).  
  8. If you have additional suggestions/recommendations, please post them in the comments!
I am not saying that I have been perfect in doing all these - far from it. So here are some of the mistakes or common error that I have done, or I have witnessed people did (if some of these describe you then You're Doing It Wrong!):
  • Send an email to co-worker about a partially described problem, then coming to that co-worker's cubicle/office and asking "Have you read my email? What do you think?". Why is this annoying? Because it's redundant and also pressuring the co-worker to immediately see/solve your problem. If you are going to send an email, send a intelligent and good description of the problem and your question. A good analogy is like creating a question/post on a forum (or StackOverflow) and then wait! If it's urgent (which is usually not), then why send an email?
  • Coming into co-worker's office/cubicle and saying "Can you come here real quick and check what I am doing wrong?" Why is this wrong in so many different levels? Because it shows an almost complete disrespect for the co-worker's attention/time/load - and expecting him/her to just drop whatever he/she is doing and solve my problem or help me. Plus, I am usually to lazy to do some research and try to articulate my problem to my co-worker - so bringing him/her to my workstation is just so much easier. 
  • Coming into co-worker's office/cubicle, describing the problem and just stand there, fully expecting the other guy to help RIGHT NOW - even some times when he already said that "give me a minute".
  • If you have additional scenarios, please post them in the comments!
Now, even if you follow all these recommendations - that does not mean your co-workers won't be mad at you and always help you with super-eagerness and save your life - I know I don't some times. But, the bottom line is that when you respect your co-workers' time, space, and attention (by minimizing interruptions), most of them will be more likely to return the favor and more willing to help you.

One exception to all of the above: if the issue at hand is URGENT (i.e. we pushing for production, crunch time, "server is down!", etc) - then all goes out the window and try to do whatever it takes to get the job done. But again, this is usually only occupies a small percentage of our work time and mostly preventable. 

Now, stop interrupting me!

-- read more and comment ...

Tuesday, April 19, 2011

Client-Side Validation with AJAX/Dynamic Form

One of the thing in my to-do list for MVC is "figure out how to do client-side validation". Isn't that supplied out of the box since like ASP.NET MVC 2? Yes, it is - but it only work out of the box if the form is not dynamically fetched.

In my projects, most of the form is a dynamic form - so user click an icon and then the form (empty or pre-filled) is fetched via AJAX and then displayed (some times in a jQuery dialog). This is a quite common scenario, for example: you are looking at your account profile screen and displayed there is a list of your phone numbers that you have registered. Let's say you then want to edit one of those since you changed your phone number. So you click the edit button/icon next to your phone number on the screen and a dialog box pops with the old phone number, you edit it, click "Save" and the list refreshes with your phone number.

To simply enforcing a "required" field validation in this scenario was quite complicated. Especially when your AJAX submit handler is a custom handler (instead of using the stock ASP.NET MVC AJAX Helper). But now, by adding less than 10 lines of code, add 2 lines of configuration settings in the web.config and including less than 3 javascripts - it is all possible!

-- read more and comment ...

Wednesday, April 13, 2011

Munchkin Strategy: Orc

An Orc card says this:

An orc who is hit with a curse can always choose to ignore the curse and lose a level instead - unless he's already at level 1.

When an orc fighting alone defeats a monster by more than 10, he goes up an extra level.
On the surface, these abilities seem to be superficial and not that powerful. Lose a level? What idiot prefers to do that instead of absorbing a curse? Extra level if defeating more than 10? Sounds either useless or extremely hard!

But, to a skilled Munchkin player, becoming an orc can be a powerful strategy in both early and late game.

-- read more and comment ...

Sunday, April 10, 2011

Utilizing pass-by-ref Parameters

I recently helped a friend of mine code an application and at some point I created a method using a pass-by-reference parameter. Apparently this is new to him. I asked several other programmer friends that I know and most of them either know about it but never use it or don't know about it. So - here is a post about it.

To illustrate the usage of pass-by-reference, I will create to a simplistic example - where we want to calculate a loan amortization: with initial loan, interest rate, and loan period - and resulting in: monthly payment and total interest over loan term

So in code, without the pass-by-reference, we have to do this somewhat in 2 steps/methods:

    decimal monthlyPayment = CalculateMonthlyPayment(initialLoan, rate, period);
    decimal totalInterest = CalculateTotalInterest(initialLoan, rate, period);
With the definitions:
public decimal CalculateMonthlyPayment(decimal initialLoan, double rate, int period) { 
        decimal result;
        // calculate monthly payment
        return result;
    }

    public decimal CalculateTotalInterest(decimal initialLoan, double rate, int period) { 
        decimal result;
        // calculate interest
        return result;
    }


-- read more and comment ...

Tuesday, March 29, 2011

jQuery update for IE9

When Internet Explorer was released, I downloaded it immediately and replaced my IE8. It works superbly except on a project that I was working on. For some reason, some javascripts are causing errors and won't work. I was using jQuery 1.4.x and jQuery UI 1.8.1.

After some investigation, the existence of the meta-tag to force IE compatibility and the outdated jQuery scripts were causing all the errors.

So I removed the meta-tag ("<meta http-equiv="x-ua-compatible" content="IE=8" />") and updated the jQuery reference to the latest greatest (1.5.1 and UI 1.8.11) - and all are happy again.

-- read more and comment ...

Monday, March 7, 2011

Munchkin Strategy: Wizard

Munchkin is a card game, where you play a character in battling monsters in order to get to the winning level (level 10 for regular or 20 for EPIC). The game involves some luck (drawing cards), strategies, a good amount of persuasion, trash-talking, and bantering back-and-forth with other players. That combination makes the game a lot of fun, interactive, and can be played again and again without getting boring.

For more information about Munchkin, you can read their website: http://www.worldofmunchkin.com/

If you are familiar with Dungeons & Dragons, then Munchkin should be somewhat familiar to you - a funny version of D&D. It has races & classes, curses, combat strength, charms, potions, etc.

The rest of this post assumes that you are somewhat familiar with the game, basic rules, and its vocabularies - outlining a basic strategy to use if you are playing as a Wizard class.

-- read more and comment ...

Wednesday, March 2, 2011

Integrating ELMAH into your ASP.NET MVC project

What is ELMAH? ELMAH stands for Error Logging Modules and Handlers. So it does what it says, logging errors. It's a plug-able stand alone module that you can integrate with your project quite easily.

From ELMAH's site:
Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code:

  • Logging of nearly all unhandled exceptions.
  • A web page to remotely view the entire log of recoded exceptions.
  • A web page to remotely view the full details of any one logged exception.
  • In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
  • An e-mail notification of each error at the time it occurs.
  • An RSS feed of the last 15 errors from the log. 
Sounds awesome! Hell yes - beats writing your own any day! How do you integrate it with ASP.NET MVC project?

1. Download ELMAH
You can get the compiled assemblies or the source files here: http://code.google.com/p/elmah/

2. Reference ELMAH's assemblies
If you get the compiled assemblies, just make a reference to Elmah.dll. If you get the source, you will need to build it and then reference it (either by project or by binary).

3. Modify web.config
Open your web.config and make these changes:
a. Add this "configSections" within "configuration"
<configSections>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
        </sectionGroup>
    </configSections>
b. Add this "elmah" section within "configuration" under the "configSections". This will enable ELMAH to save the error log to the database using "MyAppConnectionString" connection string. If you want to save the log into XML files on a local disk, you can uncomment the second line (and comment the 4th line) and specify the saving location under "logPath".
<elmah>
        <!--<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data"/>-->
        <security allowRemoteAccess="1"/>
        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="MyAppConnectionString"/>
    </elmah>
c. Within "system.web" section, add these lines:
<httpHandlers>
            <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
        </httpHandlers>
        <httpModules>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        </httpModules>
d. Within "configuration", configure the permission to see the log. Basically it will deny all users unless users are logged in and user name is listed in the "allow" list. Enable that by adding these lines:
<location path="elmah.axd">
        <system.web>
            <authorization>
                <allow users="admin,joe,bob"/>
                <deny users="*"/>
            </authorization>
        </system.web>
    </location>

4. Modify global.asax
Check in your global.asax whether this line exists:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
If it is, then no more changes are needed in the global.asax.

5. Preparing Database
If you elect to store the log in the database, then some tables and stored procedures must be created before ELMAH can be functional. Get the script to create all those tables & stored procedures here: http://code.google.com/p/elmah/wiki/Downloads?tm=2 and run it.

That should be it and ELMAH is ready to run - you can start accessing ELMAH under /elmah.axd from your root url.

But I went a step further - I want all exception, including handled one to also be captured in ELMAH. ASP.NET MVC provides an filter-attribute called "HandleError" to handle/catch all errors/exceptions happening in the controller or bubble all the way to the controller. So instead of using that, I made my own HandleError attribute that will log to ELMAH - and replace the stock [HandleError] with my [ELMAHHandleError] attribute.

6. Create [ELMAHHandleError] for all my controllers.
I took this code from NerdDinner example that ASP.NET team provides in CodePlex.
public class ELMAHHandleErrorAttribute : HandleErrorAttribute {
        public override void OnException(ExceptionContext context) {
            base.OnException(context);

            var e = context.Exception;
            if (!context.ExceptionHandled   // if unhandled, will be logged anyhow
                    || RaiseErrorSignal(e)      // prefer signaling, if possible
                    || IsFiltered(context))     // filtered?
                return;

            LogException(e);
        }

        private static bool RaiseErrorSignal(Exception e) {
            var context = HttpContext.Current;
            if (context == null)
                return false;
            var signal = ErrorSignal.FromContext(context);
            if (signal == null)
                return false;
            signal.Raise(e, context);
            return true;
        }

        private static bool IsFiltered(ExceptionContext context) {
            var config = context.HttpContext.GetSection("elmah/errorFilter") as ErrorFilterConfiguration;

            if (config == null) return false;

            var testContext = new ErrorFilterModule.AssertionHelperContext(context.Exception, HttpContext.Current);

            return config.Assertion.Test(testContext);
        }

        private static void LogException(Exception e) {
            var context = HttpContext.Current;
            ErrorLog.GetDefault(context).Log(new Error(e, context));
        }
    }

That's it!

For further reading:

-- read more and comment ...

Thursday, February 17, 2011

Mowbol Weekly: Using Corona

Mowbol.com (AWH's sister company), a company that focuses on mobile development recently did a series of videos about mobile platform. The last one was particularly interesting as it discussed using Corona to build a code once publish for both Android & iOS.

Chris Slee talks about Corona and the new Mowbol channel framework from mowbol.com.



So if you need to get into the app store fast on Android phones and tablets, iPhones, iPads, we need to talk.

You can go to mowbol's website here: http://www.mowbol.com
Mowbol also has a Youtube channel under mowboldotcom: http://www.youtube.com/user/mowboldotcom
-- read more and comment ...

Tuesday, February 8, 2011

Performance Tips (LINQ to SQL)

One part of the application that I am working on is performing poorly. According to the performance measurement that I get from using EQATEC profiler, it takes 3-4 seconds to load this page.

IIS / UI 
Since this is a web application, so I made sure all the IIS/non-application performance enhancements are in place:

  • IIS compression are turned on
  • Javascript files are combined and compressed
  • CSS files are combined and compressed
  • Images, scripts, and CSS files are cached
  • Conforming to YUI rules & Google PageSpeed performance rules
Setting all those boost some performance in my application - not really that noticeable in normal usage. It cut down about 0.5 seconds or about 13% or my load time. So now we are in 2.8-3.5 seconds range. So what else?

-- read more and comment ...

Monday, January 31, 2011

Using Except() Method in LINQ

There is a method that I rarely use in LINQ called "Except" - but it comes handy in my latest coding. So I thought I'd share how I use it. This method is for an IEnumerable and has multiple signatures: one that takes a second IEnumerable to exclude and the other one takes an IEnumerable and a comparer. You can read the spec in full here.

Here is an example:

int[] oneToTen = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] oneToTenEven = { 2, 4, 6, 8, 10 };
int[] oneToTenOdd;

// do some exclusion here
oneToTenOdd = oneToTen.Except(oneToTenEven);

// so that oneToTenOdd will have { 1, 3, 5, 7, 9 };
OK - that looks simple. But what about when the IEnumerable is of type T or some other complex type? This is where the second signature comes in handy. In this scenario, we will have to make our own comparer class to specify how we want both list items to be compared against each other.

Imagine this hypothetical situation where you are at a dealership and want to separate the cars that have been washed and ones that have not. Cars may have the same make, model, color, type, but each has different VIN number.

IEnumerable<Car> allCars = GetAllCars();
IEnumerable<Car> carAlreadyWashed = GetCarAlreadyWashed();
IEnumerable<Car> carNotWashed;

// do some exclusion here
carNotWashed = allCars.Except(carAlreadyWashed);

The above code which will normally work for simple comparison, won't work because the run-time will have no idea that it has to compare based on VIN number. We have to tell it to use that field to do comparison.

public class CarComparer : IEqualityComparer<Car> {
    public bool Equals(Car x, Car y) {
        //Check whether the compared objects reference the same data.
        if (Object.ReferenceEquals(x, y)) return true;

        //Check whether any of the compared objects is null.
        if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
            return false;

         //Check whether the Car' properties are equal.
        return x.VIN == y.VIN;
    }

    // If Equals() returns true for a pair of objects
    // then GetHashCode() must return the same value for these objects.
    public int GetHashCode(Car car) {
        //Check whether the object is null
        if (Object.ReferenceEquals(plan, null)) return 0;
        //Get hash code for the VIN field.
        int hashCarVIN = car.VIN.GetHashCode();
        return hashCarVIN;
    }
}
Now then we can modify our code to be such as this:

IEnumerable<Car> allCars = GetAllCars();
IEnumerable<Car> carAlreadyWashed = GetCarAlreadyWashed();
IEnumerable<Car> carNotWashed;

// do some exclusion here
carNotWashed = allCars.Except(carAlreadyWashed, new CarComparer());


-- read more and comment ...

Friday, January 7, 2011

Microsoft Certification exams

My employer (AWH - http://www.awh.net) encourages us (the employees) to take MS certifications. Not only this will benefit the company in maintaining our status as a Gold Partner, but also will benefit us as far as knowledge, new technology, etc. Plus the certifications are attached to the individual, so if you change jobs, those certifications certainly belong in your resume and can be leveraging points.

AWH will pay for the tests, including first failure. So if I take a test and fail, and then retake the test and pass, AWH will cover both exams. So I have to pass before the reimbursement can come through.

Anyway, so last November, I saw a promotion on Prometric's website for a 2/3/4/5 exam packets with discounted price and FREE retakes for each exams in the packet. With that good deal in mind, I decided that I will set a goal in this area: getting a MCPD - Microsoft Certified Professional Developer. This certification requires 4 exams:

  • TS 70-515 - ASP.NET 4.0, Web Forms, MVC, IIS
  • TS 70-516 - ADO.NET, LINQ, EF
  • TS 70-513 - WCF
  • TS 70-519 - Web application solution/architect
I took the first test early in December and passed it quite easily. Since ASP.NET is what I use daily, most of the questions in the test are familiar to me and I can answer them correctly.

I scheduled to take the ADO.NET test on Dec 23rd, but when I came to the facility, it was closed. I was not notified of any closing and Prometric also was not aware of the closing of the local facility (New Horizons). Prometric was able to reschedule me for Dec 27th at a different facility. I failed my ADO.NET test - probably by 2 or 3 questions, it was so close. Although I use ADO.NET stuff pretty much daily, but there are some things in there that are pretty new to me and I have not used them in production quality code - like Entity Framework. Those questions stumped me and resulting in a failing grade. Thank God for the free retake!

So I studied more EF, practice making some projects with with etc and retake the test on December 29th. I passed.

So next up is WCF - scheduled for Jan 12th. Hopefully by end of Feb 2011, I will have become an MCPD.

-- read more and comment ...