Monday, October 31, 2011

WP7–Hidden Wifi networks–Awesome Possum

Got to try out the new WP7 mango capability of being able to connect to hidden networks. It works. Nothing more to it. It was one of the features that I was waiting quite eagerly for.

It works…. Enuff said.


Saturday, October 29, 2011

WP7–NeutralResourceLanguage attribute is missing

If you get the “Neutral Resource Language” attribute is missing when uploading a XAP during app-submission, then you need to set the Neutral Language.


The Neutral Language setting is set via the project properties under the Assembly Information dialog.


Important: Once you have uploaded your app, you cannot change the Neutral Language to setting that narrows the language set. (example: if your previous version was English, then you cannot select English (United States)).

Friday, October 28, 2011

Wednesday, October 26, 2011

IIS 7–listing sites and ports used

AppCmd.exe to the rescue (c:\windows\system32\inetserv\appcmd.exe)

The command “appcmd list site” will list all the sites (and in addition will display the bindings and the ports used by the sites)

Sunday, October 23, 2011

C# debugging–an input message box

C# doesn’t have a convenient message-box that you can use for gathering user-input (which is especially useful when you are writing code for the purpose of debugging). VisualBasic has just such a form, which you can use in C#.

Add a reference to Microsoft.VisualBasic.dll

Use the following code:

Microsoft.VisualBasic.Interaction.InputBox("What would you like to do today?","To be or not to be","that is the question…");

Which creates a dialog like so:


Saturday, October 22, 2011

Bayes Network and Bayes Rule

As explained by Sebastin Thrun in the AI course:

Bayes Rule:



Whats the likelihood that a person has cancer (A) given that they have had a positive cancer diagnostic test (B)?

  • Likelihood: Probability of +ve cancer test (B) given that the person has cancer (A)
  • Prior: Probability of getting that type of cancer (A)
  • Marginal likelihood: Sum of probability of
    (+ve test given that you have the cancer x probability of having that cancer)
    (+ve test given that you don’t have the cancer (false positive) x probability of not having that cancer)

Bayes Network:



Inferring P(B):


Baye’s Rule:

Baye’s Network:

Friday, October 21, 2011

WP7 Mango–New features (part 1)

Some of the new features that I am discovering today…..

WP7 now has vision search:

  1. Take a picture of the front cover of a book – and the phone recognizes the book and returns search results
  2. Take a picture of the bar-code – and the phone searches the bar-code for results on the Internet
  3. Take a picture of text within the book and:
    1. The phone performs OCR and you can select text from the page and then perform search
    2. The phone can translate the text to whole bunch of languages.

Another feature that I have been waiting for WP7 to get is the ability to add hidden networks.

Just go to the phone settings app and check under Wifi. Under the advanced options, you can now click the plus (+) button, to add hidden networks.

Search using Bing Voice:

Thursday, October 20, 2011

Monday, October 17, 2011

Sql-Server: Determining the status of a database

I needed to determine if a database was being restored or not. The easy way is to determine the status of the database using the following script:

select [name], databasepropertyex([name], 'Status') as Status
from sysdatabases
where [name] = 'DatabaseName'

If the database is being restored, then the status will state: RESTORING

Other valid values for Status are:

ONLINE = Database is available for query.
OFFLINE = Database was explicitly taken offline.
RESTORING = Database is being restored.
RECOVERING = Database is recovering and not yet ready for queries.
SUSPECT = Database did not recover.
EMERGENCY = Database is in an emergency, read-only state. Access is restricted to sysadmin members

Sunday, October 16, 2011

C#–PriorityQueue Sample

I was reading up on Priority Queues and its been a while since I last implemented one. So I thought I would implement it in C#.

Not perfect code, but, it shows you how to implement a priority queue using a binary heap. Also, its implemented using generics, so it will support any kind of object you want to throw at it (as long as you implement IComparable). In addition, you can set the type of the PriorityQueue to be MinHeap or MaxHeap based.

Saturday, October 15, 2011

Tipping Chart

Having come from India, I am unsure of how much to tip in many situations (for example: how much do you give the wine steward) . Here is a helpful chart from


Amount of Tip


$1.00 to $2.00 per drink or 20% of the total tab.

Buffet Server

$1.00 to $2.00 per person.

Coatroom Attendant

$1.00 to $2.00 per coat checked.

Cruise Employees

It is customary to leave a tip at the end of your cruise for the following people, your cabin steward, head waiter, assistant waiter and Mater d'. The amount varies, check with your cruise line first.

Gas Attendant

It's rare these days but if they pump the gas for you they should get $1.00 to $2.00.

Grocery Boy/Girl

$1.00 to $2.00 for loading your bags in your car and $3.00 if you have more than 3 bags.


15% to 20%.

Hotel Bellhop

$1.00 to $2.00 per bag, with a $2.00 minimum.

Hotel Concierge

$5.00 to $10.00 for getting tickets or reservations.

Hotel Doorman

$1.00 per bag or $2.00 for hailing a cab.

Hotel Housekeeper

$2.00 to $5.00 per night.



Room Service

15% to 20%

Pizza/Delivery Person

$2.00 or 15% to 20%, whichever is greater.

Pool Attendant

$1.00 to $2.00 for bringing towels or chairs.

Shampoo Person



$1.00 to $2.00 per bag.

Spa Service

15% to 20%

Taxi Driver



$3.00 to $5.00


15% to 20%, more if the service is very good.

Washroom Attendant


Wine Steward

15% of the price of the bottle.

Agile software development: the principles….

Value statement:


12 principles:













taken from the PDF:

Saturday, October 08, 2011

Difference between composition and aggregation in terms of C#

Both composition and aggregations are types of associations.

An association is represented by an arrow:

An aggregation is represented by an hollow diamond:

And composition is represented by a filled in diamond:

Lets look at it in terms of a diagram: (taken from Kenny Lee’s blog)


Department is a composition, because its lifetime is dictated by the lifetime of the company object. (if a company ceases to exist, then the department ceases to exist). But on the other hand an employee is an aggregation, as a department if made up of employees, but if the department is shut down, the employees do not cease to exist. (they could get reassigned to other departments).

Here is what the code would look like in C#

public class Employee
    public string FirstName { get; set; }
    public string LastName { get; set; }

public class Department : IEnumerable
    //employees is an agreggation of employees
    private List<Employee> _employees = new List<Employee>();

    public string Name { get; set; }

    public void Add(Employee employee)

    public void Remove(Employee employee)

    public Employee this[int index]
        get { return _employees[index]; }

    public System.Collections.IEnumerator GetEnumerator()
        foreach (Employee employee in _employees)
            yield return employee;

public class Company : IEnumerable, IDisposable //implementing IDisposable just to show departments lifetime is the same as Company's lifetime
    //departments is a composition.
    //departments lifetime controlled by lifetime of Company
    private Dictionary<string, Department> _departments = new Dictionary<string, Department>();

public Company(string[] departmentsToCreate)
        Console.WriteLine("Creating the company and its departments");
        foreach(string departmentToCreate in departmentsToCreate)
            _departments.Add(departmentToCreate, new Department{Name = departmentToCreate});

    public Department this[string departmentName]
        get { return _departments[departmentName]; }

    public void ReassignAndCloseDepartmentEmployees(string departmentToCloseName, string reassignmentDepartmentName)
        Department fromDepartment = this[departmentToCloseName];
        Department toDepartment = this[reassignmentDepartmentName];
        foreach (Employee employee in fromDepartment)

    public System.Collections.IEnumerator GetEnumerator()
        foreach (KeyValuePair<string, Department> departmentKvp in _departments)
            yield return departmentKvp.Value;

void IDisposable.Dispose()
        Console.WriteLine("Company is being disposed, dispose departments too");
        _departments.Clear(); //company is dead, departments are being killed, but employees live on
        _departments = null;


public class Test

    void Main()
        using (Company company = new Company(new string[] { "EIS", "Sales" }))
            company["EIS"].Add(new Employee { FirstName = "Raj", LastName = "Rao" });
            company["EIS"].Add(new Employee { FirstName = "Arnold", LastName = "Schwarzneger" });

            company["Sales"].Add(new Employee { FirstName = "Steve", LastName = "Jobs" });
            company["Sales"].Add(new Employee { FirstName = "Bill", LastName = "Gates" });

            company.ReassignAndCloseDepartmentEmployees("Sales", "EIS");


And here is what the output looks like (in LinqPad)


The class diagram from Visual Studio


Personal observations on the reliability of the Shuttle - R.P. Feynman

Here is a Kindle version (.mobi) format of Feynman’s essay that I created. Its a good read for anybody dealing with reliability of systems (especially developers)

Personal observations on reliability of the Shuttle (kindle format)

Monday, October 03, 2011

.Net and Global Exception Handling in different types of applications

Here is how to handle global exceptions for different types of .Net applications:

1. Asp.Net:
System.Web.HttpApplication.Error event

Usually setup in Global.asax

MSDN: How to: Handle Application-Level errors.
Also see: Complete example for Error Handlers

2. WinForms:

MSDN: Application.ThreadException event

Blog: Top-Level Exception Handling In Windows Forms Applications

// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);

// Set the unhandled exception mode to force all Windows Forms errors to go through
// our handler.

// Add the event handler for handling non-UI thread exceptions to the event. 
AppDomain.CurrentDomain.UnhandledException +=
        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

3. Console applications (also should work with Windows Services – havent checked this though):
System.AppDomain.UnhandledException event

MSDN: AppDomain.UnhandledException Event

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

4. WPF:

MSDN: Application.DispatcherUnhandledException Event

public App() :base() //App.xaml.cs
        this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;

Also see: WPF Global Exception Handler (StackOverflow)

5. Silverlight:
Application.UnhandledException Event

MSDN: Application.UnhandledException Event
Also see: Silverlight Error Handling

public App()//App.xaml.cs
        this.UnhandledException += this.Application_UnhandledException;
private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e)
//handle exception here.

Also take a look at the EntLib Patterns and Practices pack for Silverlight ( {Logging Application Block}

More info:

Best Practices for Handling Exceptions (MSDN)