Tuesday, December 16, 2014

Building Fault-tolerant Software

Creating a software system or an app that can fail-safe or even fault-tolerant is not an easy task, especially for cloud apps or services since they are often platform agnostic and may require network availability.

I often ask myself how to enhance the user experience even in the unexpected user scenarios. Though the answer varies case by case for different systems and scenarios, here are some simple questions I often deliberate on when designing for error handling and fault-tolerance:
 
1. What are the corner use cases the app or system might encounter? Can system handle it?
2. In case of internal or external error occurs, can system automatically recover from the error? Can it prevent the error happens again?
3. If not, can system continue its intentional operations by providing walk-around options for users?
4. If not, can system provide users with possible manual solutions to get rid of the error?
5. If not, can system fail gracefully with proper error message for users?
6. Then, does the error need to be logged or sent for further analysis?

A simple example would be how different JavaScript websites react when the hosting browser has JavaScript support disabled (in Dec, 2014):

1. My Facebook Personal Homepage: Neither shows any content nor error message, but only an app bar:
 

2. My Live.com Homepage: Shows the proper error messages with solution:


3. My Gmail Homepage after logon: Provide user with both proper error messages with solution, and excitingly, an html version mail walk-around:

 
 
It requires extensive software validations to uncover some of software failures, and then careful design for the error handling remedy. But this process will eventually benefit the users, ITs, and developers!
 
 

Tuesday, November 18, 2014

encodeURI() and encodeURIComponent() in JavaScript.

In JavaScript, we have two utilities for encoding an URI:

encodeURI():
1) normally for encoding a full URI (given that parameters are properly encoded already)
2) encodes everything except [a-A0-9] with ~!@#$&*()=:/,;?+'

encodeURIComponent():
1) normally for encoding URI's "component" such as parameters' value in the query part.
2) encodes everything except [a-A0-9] with ~!*()'
 
1. Reserved characters in URI: http://en.wikipedia.org/wiki/Percent-encoding#Types_of_URI_characters
2. Nice article on the comparison of the two functions: http://xkr.us/articles/javascript/encode-compare/
 

Friday, September 26, 2014

Retrieving Directory Name or File Name using Powershell

# File should exist> (Get-Item 'C:\Windows\test.txt').DirectoryName
C:\Windows


> (Get-Item 'C:\Windows\test.txt').Name
test.txt


# File does not have to exist> Split-Path 'C:\Windows\test.txt'
C:\Windows


> Split-Path -Parent 'C:\Windows\test.txt'
C:\Windows


> Split-Path -Leaf 'C:\Windows\test.txt'
test.txt

Monday, August 11, 2014

Windows batch script to lookup a value or key in Registry

Find... method in RegEdit is a little tedious to use on Windows platform cauze it is looking for one instance of a search key at a time (you have to hit "Next" to get the next search result).

We could instead do the global search by the following script (regrep.bat) in command line:

@echo off
for %%a in (HKLM HKCU HKCR HKU HKCC) do (
  echo [Regrep] Looking for reg value under path %%a
  reg query %%a /f %1 /s
)
 
which could find the search term under all path recursively.
 
e.g.
 
Find a single term:
  regrep system32
 
Find a word with space
  regrep "internet explorer"