Wednesday, February 17, 2010

Career-Cup Top 150 Questions

The book is pretty easy to read.

There are over 20 chapters, each covers one area of topic, includes a short discussion and a small number of relevant problems.

Solutions to all questions are provided at the later half of the book.
http://www.docin.com/p-41796787.html
http://www.careercup.com/book

Thursday, February 11, 2010

Reservoir Sampling

Problem: Given a stream of n elements (n is unknown), sample an element with the same probability for each element in ONE pass. (e.g. given a text file with unknown number of lines, randomly print one line in the same probability for each line, using ONE pass only.)

If two passes are allowed, then it's easy since the first pass can get the number of lines, then just randomly pick one in second pass. For one pass, this does not work since total number of lines is unknown.

Solution: Reservoir Sampling.

References:
http://blogs.msdn.com/spt/archive/2008/02/05/reservoir-sampling.aspx
http://gregable.com/2007/10/reservoir-sampling.html

[Added 3/6/2010]
A straightforward way of thinking about this is:

At the n-th element, we already have a sampled element x for the first n-1 elements, now choose between x and n with the probability of (n-1)/n for x, and 1/n for the n-th element. This is is someway similar to the card shuffling algorithm.

The next extension is to sample m (instead of 1) elements out of n. Then just choose the n-th element with probability m/n, and if chosen, replace the n-th element with a random element in the previously chosen m elements.

The next extension is weighted sampling. There are discussion in the first link above.

Thursday, February 4, 2010

ASP.NET's Membership, Roles, and Profile

Pretty good introduction to ASP.NET's Membership, Roles, and Profile:
http://www.4guysfromrolla.com/articles/121405-1.aspx

Get UserId:
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();

Code to update membership property:
MembershipUser u = Membership.GetUser("member");
u.IsApproved = false;
Membership.UpdateUser(u);
Note that must use UpdateUser() method otherwise it won't update.

Wednesday, February 3, 2010

Drupal - CCK and VIEW

Use CCK and VIEW modules of Drupal:
http://learn.awakenedvoice.com/2007/07/30/drupal-cck-and-views-tutorial/
http://www.apaddedcell.com/creating-a-custom-home-page-in-drupal-using-views

- Make view column header sortable.

In Basic settings, style "table" has this option: click on the "*" to its right, in the style options panel, check "Sortable" checkbox to the fields that you want to be sortable.

- Add more fields to profile.

Default profile contains only account name and email. You can add more by using the Profiles module in Administer -> User management -> profiles.

- Show two fields in one column (The following is copied from this link):

By default, each field is its own column. However, you can place multiple fields in the same column. To do this, pick which field you want to represent the column, then pick another field and set the 'column' value to that field. You can place as many fields as you like in a single column, but only the main field in a column can be click-sorted.

This way, you can allow the user to enter first name and last name separately at registration, then show full name in a view.

Blog Archive

Followers