In my previous post, I discussed and gave a solution to the putlong() problem. However, as Christy pointed out in her comment, my code did not work if a number has trailing zeros (e.g. 15700, 3000, 10, -10, …). Christy also suggested a fix, which I have not yet verified. As I tried to correct […]
January 26, 2008
Python is such a simple and get-the-job-done language that many script I wrote is very short. Here are a couple of one- and two-liners: # oneliners.py by Hai Vu # Here are some of my one- and two-liners import os, sys # To create Pascal naming from a regular phrase print 'print in order traversal'.title().replace(' […]
January 19, 2008
I had my Leopard set up for file sharing, which I can connect from my other Mac and XP computers. However, for the longest time, I could not connect to it from my Vista machine.After doing some research, I finally found the solution posted in Apple’s discussion forum. If your user name on the Leopard […]
January 18, 2008
If you are hosting your blog on wordpress.com and would like to post your source code, WordPress has a treat for you. Check out this Java code sniffet: If you are interested, check out this WordPress FAQ page. WordPress claims to support Python, but I have tried and the syntax-highlighting feature does not work. Another […]
January 16, 2008
Here is another popular interview questions: given two rectangles, each represented by two points: an upper left (UL) and a lower right (LR) corner. Write a function that takes in two rectangles and return true if they are overlapped, false if they are not. Before we start coding, let’s take a look of the cases […]
January 15, 2008
I have been writing unit tests using C#, Java, and Python using MbUnit, JUnit, and PyUnit, respectively. Since C++ does not fully support retrospection, unit testing on C++ can be tricky. Most C++ testing frameworks require the developer to 1) write a test case, then 2) register it — a two step process. This two-step […]
January 11, 2008
This is one popular interview question. The problem: given an array which could contain zero, negative, and positive numbers, find the largest sum of contiguous sub-array. For example, if the array contains: 31, -41, 59, 26, -53, 58, 97, -93, -23, 84 then the largest sum is 187 taken from the [59 .. 97] block […]
January 5, 2008
I encountered the need to redirect the console output to a file in my attempt to automate testing of functions which does not return any value but writes to the console. Basically, we need to save the old output (Console.Out) before assigning the output to a file stream by means of Console.SetOut(). After the test, […]
January 3, 2008
This is a list of .net exceptions which I compiled. It is by no mean complete. I created this list to help me with the question, “which exception should I throw now that condition X has occurred?” The highlighted rows are the ones which I have used or plan to use. Blogged with Flock Tags: […]
January 30, 2008
0