Sunday, October 25, 2009

A better solution to a programming book's linked list problem

As astute readers of my blog know, I left my job at Sun last month. After taking some well-deserved time off, I have been looking for something new.
Despite 14 years professional experience, 20 years coding experience, and a lengthy résumé, I was stumped by some coding puzzles at a couple of large companies.
So, last monday, I picked up a book at Barnes & Noble titled "Programming Interviews Exposed, 2nd edition", to help get past the torture tests I have to endure in this tight job market. I have been reading it as a leisurely pace, trying to find the problems first on my own, before checking the solution.

I am writing this article and reprinting the problem with the author's permission.

On page 31, the author defines a typical linked-list structure :
typedef struct Element {
    struct Element *next;
    void *data;
} Element;

After some fairly basic coding discussion of linked lists, a slightly more complicated problem appears on page 35.

head and tail are global pointers to the first and last element, respectively, of a singly-linked list of integers. Implement a C function for the following prototype :

bool remove(Element *elem);
The argument to remove is the element to be deleted.


The authors spend much of pages 36-38 discussing that the problem is mostly about
"special cases", in particular when deleting elements at the beginning or the end of the list.

The author's final solution reads as follows :
 
bool remove(Element* elem) { 
    Element* curPos = &head;

    if (!elem)
        return false;

    if (elem == head) {
        head = elem->next;
            delete elem;
        /* special case for 1 element list */
        if (!head)
            tail = NULL;
        return true;
    }
    while (curPos)  {
        if (curPos->next == elem) {
            curPos->next = elem->next;
            delete elem;
            if (curPos->next == NULL)
                tail = curPos;
            return true;
        }
        curPos = curPos->next;
    }
    return false;
}
 
While my first inclination was to also have a special case, I quickly stroke that part out on paper. I think the code really does not have to be so long if you use a double pointer to refer to the
head. This eliminates the first special case for updating the head pointer when removing the first element. And therefore, there is no longer a need to update the tail pointer in two different places, which further reduces code size.

bool remove(Element* elem) {
    Element** curPos = &head;

    if (!elem)
        return false;

    while (*curPos) {
        if (elem == *curPos) {
            *curPos = elem->next;
            if (elem == tail)
                tail = elem->next;
            delete(elem);
            return true;
        }
        curPos = &((*curPos)->next);
    }
    return false;
}
The only thing I changed from my piece of paper was the name of the temporary variable, and the formatting, to match that of the book's authors.

Friday, October 2, 2009

Better not get sick at Netflix !

This post is more than 2 years overdue, but I felt that my story needed to be heard, especially by past, current and prospective Netflix employees, as well as management.

In the summer of 2006, I was looking for a new position and ended up interviewing and landing what I thought was a great opportunity at Netflix working on security in the Electronic Delivery Systems group, and with a hefty paycheck. My first day was October 31, 2006.

Unfortunately, on November 1, my second day there, I got very bad news from my physician : my HIV test, performed the week before, had turned positive. This was of course devastating news. I became severely depressed, and was not able to make it to work on my third or fourth day. I missed plenty more work time. My boyfriend also turned out HIV positive 2 weeks after I did. I will be the first to admit that I was completely ineffective at my job for the next 2 months. Learning both about this new major disease and a new very challenging job at the same time simply was more than I could chew.

Finally, in January of 2007, I went on short-term disability for the depression and ended up in IOP at Kaiser. I was covered under Netflix's generous disability policies. After 1 month, I had still not been released back to work, and received a letter with an ultimatum to return to work by mid-february, 6 weeks after the start of my disability, or be terminated.

Unfortunately, I was ineligible for an FMLA, a Family Medical Leave of Absence, which would have allowed me to take 3 months medical leave, because I was a recent hire, and the law only covers those with at least 1 year of service.

One week before the ultimatum, I pleaded my case with Netflix HR, explaining the reason for my absenteism and disability. This did not make any difference. I was told that it was standard company policy for this situation - to terminate the new employee who had an extended illness ! The date passed, and I was terminated while still on disability. That was the first and only time I had ever been involuntarily terminated. No severance of any kind was offered. I was now both HIV positive, and jobless.

I was released by my doctor to work again about a month after my termination, and returned to my previous employer, Sun Microsystems, another month later, working 60% (3 days a week) for the remainder of 2007, and then back to full time in 2008.

As I write this post, I am enjoying some much-needed time off, having left Sun out of disinterest in September in the wake of the acquisition of Sun by Oracle, and seeking another opportunity. Few Silicon Valley companies are hiring at this time. But I noticed that Netflix was, and my old position still had not been filled. I inquired with my former manager at Netflix, who was aware of the details of the situation. I was told that per Netflix company policy, there are no second chances there - once you are fired from Netflix, you can never apply there again.

The moral of the story is this : make sure you don't get seriously sick if you want to work for Netflix, especially in your first year.

Saturday, September 26, 2009

Windows 7 vs Fedora Core 11, and Linux in general

This year, my father also wanted to upgrade his computer, as did my mother. I had a shop build one with the exact same parts. I imaged my mother's computer drive with Acronis, and imaged it back to my father's computer. So far so good. But I had installed Windows 7 with its default setting, which creates two partitions - a "recovery partition", which was about 100 MB, and a regular Windows 7 NTFS partition, which was about 931 GB.

My father has been a Linux user for a very long time, and only desired Windows for very occasional use. In the past, it was fairly easy to dual-boot Windows & Linux. Not so this time.

First, I had to shrink the Windows NTFS partition using the "shrink" tool. But this didn't work. There were a variety of unmovable system files towards the end apparently. Even after defragmenting the drive, the shrink feature of the Windows disk manager could only reduce the drive by a measly 300 MB ! The solution was very complicated : I erased all the partitions, reinstalled Windows 7 with a small partitions, and then re-restored my mother's computers into the small partition from my backup drive using Acronis True Image 2009. Now, I had a working Windows 7 installation, and some free unpartitioned space.

The next 3 days were spent trying to install various versions of Linux, mostly Fedora Core 11 64 bits, as well as Ubuntu 8.x. This was always unsuccessful. Typically, the Fedora installation program just crashed with exceptions. Just hours before I was supposed to leave, I got the idea to delete the 100 MB Windows 7 recovery partition. I then restored its content from the Acronis backup onto the large Windows partition, and booted with the DFSEE tool to make the Windows 7 partition active. But Windows 7 still didn't boot correctly. I then booted the Windows 7 DVD and used the recovery option. Amazingly, that worked. I now had a single 212 GB NTFS Windows 7 partition that was booting. After that, the Fedora Core 11 installation proceeded like a breeze.

Moral of the story : if you want to dual-boot Windows 7 and Linux - do not let the Windows 7 installer create the recovery partition when you get prompted to let Windows create additional partitions. Just say no !

Windows 7 vs LSI Logic 53C1030 Ultra160 SCSI controller

I have been using SCSI controllers in one form or another in some of my PCs for over 15 years. At this time, I have only a couple of SCSI devices left - one 36 GB hard drive made by Seagate that spins at 15,000 rpm, and a DAT DDS-4 tape drive made by HP. The last SCSI controller I bought was purchased in 2001 and is based on the 53C1010 Ultra160 SCSI chipset by LSI Logic, formerly Symbios, formerly AT&T, formerly NCR. This chipset worked wonderfully under a variety of operating systems, from OS/2 up to and including Windows Vista x64.

Enter Windows 7. Earlier this wednesday, I attempted to migrate the system containing this SCSI controller from Windows Vista x64 to Windows 7 x64. I was told that there was no driver for Windows 7 for the controller. This was quite disappointing, after 8 years of loyal services. I disabled the device in the device manager, and proceeded with the installation of Windows 7 anyway.

At the time of this writing, I have been unable to locate a proper driver for this controller under Windows 7 x64. This means the OS can no longer see my two SCSI devices. I don't care much about Windows no longer seeing the DDS-4 tape drive as I wasn't using it under Windows. But I am bothered by no longer seeing the SCSI hard drive, which still contains a bootable copy of OS/2 Warp Server for E-Business SMP. While that SCSI hard drive is formatted as HPFS, and can therefore not be mounted under Windows 7, it could still be imaged and backed up with Acronis True Image Home, at least under Windows Vista back when the SCSI controller worked. I may end up going back to Windows Vista on this system if I can't resolve this issue. Or I might move my OS/2 installation to another drive.

Windows 7 vs Kaspersky Anti-virus 2009

I recently acquired the above anti-virus for the low of sum of "FAR" (free-after-rebate), ie. I only paid the sales tax on it. This is a good program that performs well under Vista x64.
When I attempted an upgrade of one of my computers to Windows 7 RTM (final version), the installation program instructed me that KAV was incompatible with Windows 7. I was forced to uninstall it before proceeding with the upgrade to Windows 7. At the time of this writing, Kaspersky only has a beta program for Windows 7. I hope they will issue fixes soon, as Windows 7 final version has been available to developers for a month.

Windows 7 vs Acronis True Image Home 2009

For the last 6 months or so, I ahve been using the excellent Acronis True Image Home 2009 software to image the hard disks of several home computers under Windows Vista x64. During a recent trip to France, I traveled with a hard drive containing a drive image so I could get to all my files.
To my dismay, I found that I was not able to fully access the data under Windows 7 (RTM, ie. final version). True Image Home 2009 still has some issues under it. Specifically, at the time of this writing, it's unable to mount drives from the backup archive as local drive letters under Windows 7. All is not lost, since the restore feature of True Image still works. However, it takes much longer. I wanted to mount the drive to use the command-line XCOPY program to only copy certain types of files from the archive. Unfortunately, the True Image Restore feature is limited, and does not allow such file filters. I ended up having to restore a full directory, and then deleting all the unwanted files, which took much longer - in fact about 4 more hours than it should have.

Let's hope that Acronis will issue a patch for True Image 2009 to fix the drive mounting issue under Windows 7.

Video memory setting in VirtualBox with 30" monitor

In recent months, I have been running Sun's Virtualbox software to run multiple guest operating systems. One of my two monitors is an HP LP3065 30" LCD, which has a 2560x1600 resolution (4 million pixels).
Virtualbox has a very nice feature which allows the desktop to be resized up to the host's resolution. In theory. When I tried to use the feature, I noticed that the guest couldn't be maximized. The reason turned out to be that the default video memory in Virtualbox was insufficient. 2560x1600 at 32 bit color depth requires 16384000 bytes of video memory. Once I increased the video memory to 16MB, I was able to maximize the guest OS window to fill up the entire screen.

Wednesday, September 23, 2009

Windows 7 ATI HDMI audio vs digital coax audio issue

A few weeks ago, I was in France. I took advantage of the occasion to upgrade my mother's computer to much more recent hardware, as well as her television to a new 46" LG LCD HDTV. The PC was setup with the final version of Windows 7 x64.

She kept her old PC monitor, a 15" LG LCD, with only a VGA connection, as well as her old Yamaha RX-V420RDS amplifier, which long predated HDMI.

The PC sported a Sapphire video card with an ATI Radeon HD4850 chipset and dual DVI outputs. One output went to the 15" LCD with a DVI->VGA adapter, and the other went to the TV with a DVI->HDMI adapter and a 15m HDMI cable.

The PC audio was connected to the digital coaxial input Yamaha amp via a 15m coaxial cable.

After I taught her how to switch back & forth between her 2 displays in Windows 7, my mother noticed a very odd problem : when she was using the TV as her display, all sound disappeared ! But when she switched back to the 15" analog VGA LCD, it came back. I was unable to debug the issue for her over the phone. But I still had some more time before flying back home, and determined the root cause of the problem in person : Windows 7 had seen it fit to automatically redirect all audio to the HDMI output of the video card when the display was switch to the TV !

This was of course not what was desired for her setup. The TV's audio was muted and we had no intention of using its built-in speakers. We wanted the audio to always stay on the digital coax output hooked up to the Yamaha amplifier . I fixed this in the Control Panel by disabling the ATI HDMI audio output device. I hope this will help someone else running into the same issue of lost sound when switching displays.

Monday, August 10, 2009

Amazon reviews

A little over a year ago, I purchased an expensive Panasonic LM-BE50DE dual-layer rewritable Blu-ray disc. This 50 GB media cost me $50 from Amazon. It worked fine, so I posted a positive review, which has since received 3 helpful votes.

A year later, the disc has failed. And Panasonic won't replace it because they only have a 90 days warranty on parts, which includes media !

I attempted to change my Amazon review's star rating down from 4 stars to 1 star. But it was impossible. I could only change the headline and text of the review, but not the star rating. I called Amazon about this, and was told that this could only be done within 30 days of a review ! I think that makes Amazon reviews significantly less helpful if long-term owners of a product cannot update their reviews when they later encounter problems with them.

To be fair to Amazon, it appears that it's possible to delete the review, and post it again. I haven't tried that. But doing so would void the helpful votes that my original review received.

Sunday, August 9, 2009

Annoying Cubase license scheme

Last week, I bought a pair of Yamaha KX61 keyboards to replace a broken organ. They came with a limited version of Cubase software, called Cubase AI. Unfortunately, the software refused to install on my Vista 64 box, crashing in the annoying license checker scheme. The exact error message was Syncrosoft Protected Object Server has stopped working.

After much research, I found the solution to this problem :
1. Disable DEP in Control Panel/System/Advanced/DEP
2. Reboot the computer
3. Reinstall Cubase
4. Re-enable DEP, with the exception of the SYNSOPOS.EXE program., which lives in the C:\Program Files (x86)\Syncrosoft\POS on my system, but might be in C:\Program Files\Syncrosoft\POS for those with 32-bit systems.

Thursday, June 25, 2009

Obama putting gays back in the closet

After making strong promises to the gay community on national television, such as the repeal of the military Don't ask don't tell policy, and the repeal of the Defense of marriage act which he once called abhorrent, and getting elected on those promises, Barack Obama now no longer wants to say anything on the subject matter. Except in private, secret meetings. In other words, he would much rather have us keep quiet, in the closet. Those times have passed, mister President.

Tuesday, June 23, 2009

Naked DSL and Cable Internet without TV

These days, I make most of my telephone calls either from my (pricey) cell phone, or over the Internet. I have little need for my landline telephone line. Except I'm forced to pay for it because it is required to have DSL service with my current Internet service provider. The service runs over AT&T landlines. While AT&T has made "naked DSL" available to its customers, this only applies to those who subscribe to the AT&T internet service. Not to other internet services running on the AT&T cicruits. So, I'm subscribing to a $7.28 measured rate service. To which $6.88 of various taxes and fees are added, for a total of $14.16. For a service that I don't want or need. For over 7 years. This should be against the law.

Lately, I have been thinking about switching over to cable internet, because much higher download and upload speeds are available. However, once again, one is forced to purchase unwanted basic cable TV service when ordering cable internet from Comcast. I get my TV service by satellite and over the air, and have no use for cable TV. It appears that Comcast is now relaxing this requirement to purchase basic cable, but only for one of the lower speeds, and for a temporary introductory period of 6 to 12 months. After that, the monthly rate more than doubles, due primarily to the extra added cost of the unnecessary basic cable TV service. Once again, this bundling of service should be against the law.

Monday, June 22, 2009

Murder by the state : people with HIV to be terminated in California

The governator's proposed California budget includes $55 million of cuts to the AIDS drug assistance program. This program serves 35,000 people in California who are either uninsured, underinsured, or uninsurable, and need to take their HIV medications daily in order to survive. Any missed dose of medication can lead to drug resistance, and the medication stops being effective. This ultimately leads to the need for even more expensive medication, or to death.
With this new budget proposal, the governor is quite explicitly proposing to murder 35,000 HIV/AIDS patients by way of withholding their treatment. The cost of an HIV regimen typically starts at about $1,500 per month and most people on ADAP had no other way to pay for it.

The size of the annual California budget deficit is $24 billion. These ADAP cuts represent less than 0.2% of the state deficit. Apparently, there must be some higher priority than California citizens' life in the rest of the budget.

What distinction do these 14 countries share ?

The USA, Brunei, Egypt, Iraq, Yemen, Malaysia, Oman, Qatar, Singapore, Sudan, South Korea, Tunisia, Turks & Caicos Islands and the United Arab Emirates.

Stumped ?

They all still ban foreigners from visiting and migrating specifically on the basis of an HIV-positive status.

And how do they find out who is positive if the person does not declare it, you might ask ? By random bag searches at the borders. Anyone found with their HIV medications, which have to be taken at least once daily without fail, is sent back.

Rice recipe with pressure cooker and induction cooktop

I am a big fan of rice. But not of the time it usually takes to prepare it. A few years ago, I bought a rice cooker from Costco. It took over 45 minutes to steam just a couple cups of rice that I wanted to have for dinner. Everything else in my meal was ready long before. I found this unacceptable. The rice cooker went back to Costco.

So, in 2006, I purchased a pressure cooker. This is a 6qt model from the Fagor Splendid line. It is relatively inexpensive, and made in Europe. I bought it at a local retail store in Santa Clara.

Having remodeled my kitchen the year before, I was the proud owner of a Kenmore 30" induction cooktop model 42800. I decided to experiment with the pressure cooker and this cooktop to get rice much faster than any steam rice cooker can. This article is about my current recipe. The total cooking time is only about 6 minutes.

Ingredients :
1. rice . I chose some Basmati rice from Costco. I have been using 1 to 5 cups with this recipe, I haven't really tried more.
2. water. With the rice I chose, I use 1.5x the volume of rice. This will vary depending on what type of rice you purchase. But once you know the correct volume, you need to measure exactly, as measurement errors are sure to make your rice either burn or be wet.
3. chicken broth cubes, 1 to 2. I use some Knorr brand.
4. PAM cooking spray
5. herbs. I use some thyme mostly.
6. olive oil .
7. salt
8. pepper

Steps :
1. spray the bottom of the pressure cooker with PAM . This is very important to avoid sticking. If you forget, washing will be much harder.
2. measure water volume and pour it into the pressure cooker
3. put the pressure cooker on the strongest burner and start boiling. On the Kenmore unit, this would be the top-left one. I use the highest P booster"setting.
4. mix in the chicken broth, olive oil, salt, pepper and thyme
5. while the water is boiling, wash the rice.
6. since induction is so fast, the water will probably be fully boiled in 1 minute, before you are done washing the rice :) Pour the rice into the boiling water as soon as you can.
7. put the lid on the pressure cooker and close the valve
8. wait until a significant amount of steam starts to release. This will take about one minute typically.
9. turn down the cooktop setting a little bit, to the 9 setting (non-booster) and let cook for exactly 2 minutes. Don't use an analog timer or watch for this. You need to be exact and use a digital one.
10. turn down the setting a little bit more to 8, and let cook for exactly 2 minutes. Again, use a digital watch.
11. turn off the cooktop. steam should stop releasing immediately.
12. turn the valve to release all the steam. This will take about a minute.
13. open the pressure cooker
14. serve.
15. clean the pressure cooker. This is the worst part, since it is not dishwasher safe.

Personally, I find the resulting taste and consistency of the rice to be much better than what I obtain in the rice cooker. And of course in less than 10 minutes of total preparation, versus over 45 minutes with a rice cooker.

Disclaimer :
I have a lot of asian friends. Not all of them agree that this rice tastes better than when made in a rice cooker. Some cannot tell the difference.

Sunday, June 21, 2009

Share on ovi disaster

I guess some things in life are too good to be true.
The web site Share on ovi , operated by Nokia, had been offering unlimited image hosting, for free. It included such great features as the ability to retain the original picture size and let viewers see it, as well as on-the-fly resizing, sorting by shooting date, creation date, etc. It was everything I wanted in a picture hosting site, and for free ! I uploaded about 4GB of pictures from my Pentax K200D DSLR to ovi in the past year. Only to find out that the site no longer has any of its useful features. Viewers can only download a very small reduced picture, all the sorting is gone, etc. There isn't even an option to pay to get these features back. They are just gone. So, I'm now faced with the prospect of finding a new picture host. It probably won't be a free one. But I hope it's one that won't become useless soon after I start using it.