A simple vow

Starting tomorrow, I will continue to greet and speak to my Chinese friends as if nothing has changed. However, in order to show my love and solidarity towards a homeland on which I once felt like an outcast,  I will, from now on, go out of my way to avoid buying “made in china” products. This is but one in many examples of why:

This ain’t gonna be easy, as it excludes any future possibility of owning an iPad. But it’s the principle of the thing.

Workaholic culture (still)

From the Twitter Engineering blog:

While on vacation in Germany, Michael Busch, one of our search engineers, implemented a demo of image and video search. A few weeks later, during Twitter's first Hack Week, the search team, along with some members of other teams, completed the first demo of our new search experience. Feedback from the company was so positive that the demo became part of our product roadmap.

Impressive. But it reminds me of this CNN article I saw the other day, Why is America the 'no-vacation nation’?,  which starts with this line:

Let's be blunt: If you like to take lots of vacation, the United States is not the place to work.

I think this all started when I brought my sleeping bag into work one day back in 1999. Depressing.

Them’s fight’n woyds!

Expensify‘s CEO on “Why we don’t hire .NET programmers”:

Programming with .NET is like cooking in a McDonalds kitchen.  It is full of amazing tools that automate absolutely everything.  Just press the right button and follow the beeping lights, and you can churn out flawless 1.6 oz burgers faster than anybody else on the planet.

So what’s the moral of this whole story?  Two things:

  1. If you ever want to work in a startup, avoid .NET.  It does you no favors.
  2. If you are a startup looking to hire really excellent people, take notice of .NET on a resume, and ask why it’s there.

I recently knew of Expensify by reading this blog entry by Phil Windley. I can only guess from Mr. Barrett‘s conclusion that Expensify gets alot of resumes from .NET developers. From the employer’s perspective, following the law of averaging, it makes perfect sense. If your software platform is Linux, PHP and Bash, why would you hire a .NET developer? Rather, underlying the above two points is an implicit advice to startup employers—don’t use .NET technologies—which, I daresay, is ill-conceived. But hey, I’m not a CEO of a company. Not yet anyway. ;-)

In the end, probably nothing more than simply a publicity stunt.

What to do when CryptAcquireContext() fails

I’m using CryptoAPI to do encryption and encountering an error on Win2008 Terminal Server which enforces Mandatory Profiles. CryptAcquireContext() fails with a message of either “keyset not found” or “The profile for the user is a temporary profile”.

I’ve tried the same test on WinXP using a guest account and got the same thing.

So, what gives?

Well, this blog post (RSACryptoServiceProvider fails when used with mandatory profiles) way back in 2007 by @alejacma explains:

CryptAcquireContext will fail with NTE_TEMPORARY_PROFILE error when called from a mandatory profile.

Mandatory profiles are read-only user profiles. Since changes to the mandatory profile cannot be saved, PKI design doesn't allow this operation, and CryptAcquireContext prevents this scenario by failing.

The moral of this story is: RSA sucks, and I am now Rijndael’s new biggest fan.

By the way, troubleshooting this problem had given me the chance to learn a few more WinDbg commands:

.sympath srv*http://msdl.microsoft.com/downloads/symbols
.sympath+ c:\localsymbols
.reload –f
bm /a advapi32!CryptAcquireContext*

6 months

The following event is happening to me now. There is a certain business Internet service provider in Toronto whose sales guy signed me up on an agreed network speed, whose installation technician, upon arrival at our site, made a judgment that they could never provide service at said speed and aborted the install, who sent us a bill 30 days later for service never rendered, which thus far has taken me 6 months to fight for a refund. I’m stuck with a jaded feeling as I sit here now preparing to fax back a copy of the receipt proving to them that I did indeed return their modem. This internet provider uses a third party to process equipment returns.

The following event happened to me a couple of years ago. There is a certain home building materials vendor in Toronto, who uses a third party for their credit provisioning, who miscalculated my returns on their monthly statement, which took 6 months for me to successfully dispute the discrepancies.

A couple of conspiracy theories is now bubbling in my head.

XmlSerializer and the "Specified" suffix

It took me 3 hours to figure out why XmlSerializer wasn’t writing out a particular class property. This is why:

…if a serializable Field/Property has a corresponding field of type Boolean having as a name the Field/Property name with "Specified" suffix, the XmlSerializer conditionally exclude that Field/Property from the serialization process.

DateTime Serialization to XML

I have an C# serializable object with a DateTime property like this:

        public class MyClass {
public DateTime Date1 {get;set;}
}

When serialized to XML, it gives me something like this


        <MyClass>
<Date1>2010-11-30T00:00:00</Date1>
</MyClass>

I could not get it to give me this, which is in the proper  xml date format:


        <MyClass>
<Date1>2010-11-30</Date1>
</MyClass>

After a couple of wasted days, it turned out that the solution is really simple:


        public class MyClass {
[System.Xml.Serialization.XmlElement("Date1", DataType="date")]
public DateTime Date1 {get;set;}
}

Does your employer own your side projects?

Apparently, according to Joel Spolsky, they do:

…So before you hire this guy, you agree, "hey listen, I know that inventing happens all the time, and it's impossible to prove whether you invented something while you were sitting in the chair I supplied in the cubicle I supplied or not. I don't just want to buy your 9-5 inventions. I want them all, and I'm going to pay you a nice salary to get them all," and he agrees to that, so now you want to sign something that says that all his inventions belong to the company as long as he is employed by the company.

This is where we are by default. This is the standard employment contract for programmers, inventors, and researchers.
[Read rest of the discussion at answers.onstartups.com…]

One Interesting corollary: if you spend your day-time working for an employer and night time working on a github open source project, and 2 years from now the OS project becomes wildly popular (wink), your open source project is probably not very “open” afterall, unless you’ve had the appropriate work-for-hire clauses stipulated in your employment agreement. I’m reminded of a vaguely similar case in recent history: the infamous SCO v. IBM debacle from a few years back.

Convert string to DateTime object

Two C# functions that may be useful in accepting date/time strings of various formats:

        /// <summary>
/// Converts date string value, of various formats into DateTime object.
/// Example formats are DDMMYYYY,DD/MM/YYYY,MM/dd/YYYY,MMDDYYYY,...
/// </summary>
/// <param name="dateValue">date string</param>
/// <returns>resulting DateTime object</returns>
public DateTime ConvertDateStringToDateTime(string dateValue) {
string[] dateFormats = { "MM/yyyy",
"M/d/yyyy", "M/dd/yyyy", "MM/dd/yyyy",
"dd/MM/yyyy", "ddMMyyyy","dd/MM/yyyy","MMddyyyy",
"MM-dd-yyyy" };
try {
return DateTime.ParseExact(dateValue, dateFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);
} catch (FormatException fe) {
throw new DataException(dateValue + ": " + fe.Message);
}
}

/// <summary>
/// Converts a time string of various formats into a DateTime object.
/// Example formats are: 7:00,700AM, 7:00AM, 7:00A, 0700AM, 07:00 AM, ...
/// </summary>
/// <param name="timeValue">time string</param>
/// <returns>resulting DateTime object</returns>
public DateTime ConvertTimeStringToDateTime(string timeValue) {
string[] timeFormats = {"HHmm","Hmmtt",
"H:mm", "H:mmtt", "H:mmt", "HHmmtt", "HH:mm tt", "HH:mmtt","HH:mmt", "HHmmtt", "HHMMt"};
// DateTime string cannot be blank, so if it is, assume "00:00"
if (string.IsNullOrEmpty(timeValue)) timeValue = "00:00";
try {
return DateTime.ParseExact(timeValue.ToUpper(), timeFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);
} catch (FormatException fe) {
throw new DataException(timeValue + ": " + fe.Message);
}
}

Blog v3.0

This old techie blog of mine seemed to be dead silent lately that I feel compelled to resurrect it.

Let’s review a bit of history: In my mind, version 1.0 of my blog was on Bloglines (circa 2004). Version 2.0 was when I switch to blogspot and using the Kubrick theme.  It’s now time once again to resharpen the toolkit, beginning with a fresh new look, hat tip to the fine folks at Deluxe Templates for the iNove theme

TODO: I like this theme, but one thing I might change is to make a little more room for the content pane.

Also trying to install Alex Gorbatchev’s SyntaxHighligher scripts. Let’s see if this works:

    /**
* Sample code in C# to test SyntaxHighlighter.
*/
public Argument ArgueWith(Person person) {
if (person == null) {
throw new ArgumentException("no object to argue with");
}
// prepare argument
Argument arg = new Argument(person);
return arg;
}


Update 01/30/2011 11:44pm EST: SyntaxHighlighter worked great. I had to use dropbox.com to host the scripts. I think I spotted a bug, though, on Safari for iOS 4.1: line number is a bit out of whack.  Let’s have a closer look at PasteBin, as Gavin suggested: