Sergio and the sigil

Don't be sloppy in your scripts

Posted by Sergio on 2008-11-14

For a few weeks now, every time I try to logoff from my home banking website something bad happens. See screenshot below.(screenshot eaten by backup failure.)

  1. Firebug opens unexpectedly
  2. There's a frigging debugger; statement in the live production site
  3. The logoff process hangs until I press F8 in Firebug or the continue button
  4. All my information is still on the screen. Imagine if I had just clicked Sign Off and left my desk.

When I saw this for the first time I though: wow, some developer will be slapped for that (actually there are some developer names in the file,) but it seems that nobody else has a debugger enabled or they just hate their clients that are also web developers. The "bug" has been there for at least 2 weeks now.

Even if you don't care for customers that happen to have a debugger like myself, leaving that kind of thing in your production environment immediately projects an image of sloppiness that is the last thing I want to have with my home banking.

Update 11/24/2008: That script was fixed sometime over this past weekend.

TIP - Disable full row selection in Vista's Explorer

Posted by Sergio on 2008-09-30

I've been using Vista since the official release (skipped the betas) and I've been trying to convince myself that some of the changes were made for the better.

In particular, I've made some effort to get used to the new file explorer but somethings have been harder to put up with. Anyway, little by little I "fix" some of the new features.

Today, I had it with the unnecessary full row selection. It makes right-clicking the directory listing background much harder. The fix isn't trivial. It involves setting a bunch of flags in the Explorer settings in the Registry. The good news is that you can get it in a .vbs file (I don't recommend downloading and executing scripts from the Internet, so open the file in a text editor and inspect what it does to make you feel comfortable with what it does). There are other handy utilities there as well (Update: site seems to have vanished. I updated the link to a copy of the script I had. I could not contact the author to verify if it was ok to redist the file, though).

Next up is changing the selected/hovered-over item's background color in Explorer (Aero). That choice of blue is way to pale for me. I've read that it cannot be changed easily because it comes from a bitmap embedded in the theme itself.

By the way, I'm mainly using Windows Server 2008 with Aero turned on and the fix works there too.

The bug that almost drove me mad, and it's not my bug

Posted by Sergio on 2008-09-22

No bug in Windows (XP and 2003) has annoyed me more than the one I just learned how to get rid of.

For no discernible reason, while using the Windows Explorer the treeview on the left would just go bananas and display multiple Desktop icons. As seen in the following image. The additional Desktop icons sometimes had other Desktop as children. A recursive bug, nice.

I had been experiencing this bug for many years in both XP and 2003. The most frustrating part of it was that anyone seemed to have seen similar bug on their boxes. I had that problem in every single XP or 2003 boxes I had ever had. Including virtual machines. That led me to believe it must have been caused by some software that I use on all boxes. Nope. Keep reading.

After years of internet searching for people with similar problem, posting to message boards, and almost scheduling an appointment with a shrink, today I found this thread with other poor souls suffering of the same pain.

Without further ado, I present you the culprit.

Yes, my friends. The seemingly innocuous and handy Desktop taskbar toolbar has been that thorn, that little and continuous disturbance that contributed to loss of precious hours of my working and leisure time (when computing all the times it happened in the last 6+ years I've been on Windows XP). Removing that toolbar from my taskbar made the problem go away. I have the same toolbar on my Vista and 2008 taskbars and have yet to see that problem there.

Apparently an abysmal fraction of Windows users care for that toolbar so nobody cared to report the bug. That or everybody else was aware of that bug and skipped the toolbar altogether. In either case, poor me :)

Today I'm glad to cross out that problem from my infinite list of things to figure out some day. I can still get a working Desktop toolbar by adding a new toolbar that points to the Desktop directory in my user profile directory. It does not combine with All users but it's good enough for how I use it.

Tip: export to CSV using ADO.NET

Posted by Sergio on 2008-09-17

A friend of mine was telling me about a bug he found in one of his applications caused by a simple lack of escaping quotes when producing CSV files. It immediately reminded me of an old trick in .NET.

If you really want, you can create CSV files using ADO.NET and OLE-DB (or ODBC.) I wouldn't necessarily recommend this approach but it is definitely one of those things that when you see for the first time you go "I never thought this could be done this way."

The idea is simple — open an OLE-DB connection using the Jet OLE-DB provider, create a table (which is really just a file) and insert rows in that table (or lines in that file.)

//create a temp directory for the CSV output
string tempFile = Path.GetTempFileName();
File.Delete(tempFile);
tempFile = Path.GetFileNameWithoutExtension(tempFile);
string dir = Path.Combine(Path.GetTempPath(),  tempFile );
Directory.CreateDirectory(dir);
string csvFile =  Path.Combine(dir, "data.csv");

string cnStr = 
    "Provider=Microsoft.Jet.OLEDB.4.0;" + 
    "Extended Properties='text;HDR=Yes;FMT=Delimited';" + 
    "Data Source=" + dir + ";";

using (var cn = new OleDbConnection(cnStr))
{
    cn.Open();

    //define the file layout (a.k.a. the table)
    var cmd = new OleDbCommand(
        "CREATE TABLE data.csv (CharColumn VARCHAR(30), IntColumn INT)", cn);
    cmd.ExecuteNonQuery();

    //start pumping data
    cmd = new OleDbCommand(
        "INSERT INTO data.csv (CharColumn, IntColumn) VALUES (?, ?)", cn);

    //in a more realistic example this part
    // would be inside some type of loop

    //1st record
    cmd.Parameters.AddWithValue("?", "11111111");
    cmd.Parameters.AddWithValue("?", 1234);
    cmd.ExecuteNonQuery();

    //2nd record
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("?", "22222\"22222");
    cmd.Parameters.AddWithValue("?", 6789);
    cmd.ExecuteNonQuery();

    //etc...
}

//read the csv formatted data
string csv = File.ReadAllText(csvFile);

//cleanup
Directory.Delete(dir, true);

Console.WriteLine("Result:");
Console.WriteLine("--------------------");
Console.WriteLine(csv);
Console.ReadLine();

The output of this will be as follows. Note the escaped double quote in the last line.

"CharColumn","IntColumn"
"11111111",1234
"22222""22222",6789

Of course, you can also read from a CSV file with simple SELECT statements against the file. You can let ADO.NET take care of all your typical CSV tasks.

Fabrice Marguerie wrote about this same topic a long time ago (check the comments and links too).

You may also want to check a more structured approach to the Export to CSV problem by way of the FileHelpers Library.

Software I can't work without

Posted by Sergio on 2008-07-31

I'm about to configure a new development machine this week. It's going to be my 3rd install from scratch in the last 12 months, which I know is not all that much, but certainly more than I wish I had to.

Besides the common software development tools, like Visual Studio, SQL Server, Ruby, Office, Firefox, SVN, etc, over the years I've collected a number of small tools that I make sure are installed before I start doing anything else.

The list is volatile but some utilities have been there for years. Here's my current list in no particular order:

  • Taskbar Shuffle - I'm sort of a neat freak and this little wonder does only one thing. It lets you rearrange the application buttons in the taskbar. I don't understand how this is still not enabled in Windows out of the box. UPDATE: We have been heard. Windows 7 finally allows you to rearrange the taskbar buttons.
  • Slickrun - I need a command/app launcher and I've settled on Slickrun for some time now. I don't need much from it but I definitely need it. On my mac, as you can imagine, I use Quicksilver.
  • EditPlus - Every serious developer has his favorite text editor. Mine is EditPlus, at least on Windows. It's simple, extensible, has most of the features you'd expect from a text artisan's toolbox. Again, on the mac I'm more obvious and use TextMate, which is quickly becoming my new favorite if I can work on the mac.
  • Truecrypt - In case you aren't familiar with it, Truecrypt is a data encryption software that creates encrypted file systems that that you can mount in Windows, Mac OS X, and Linux. Truecrypt makes encryption a piece of cake and I have been using it since when it's non-Windows support was laughable.
  • Timesnapper - This tool has a very simple premise, it takes screenshots of your desktop on a regular interval. You can later relive your day just like a movie. This application is like my backup memory when I'm preparing my timesheets. It works great with Truecrypt in case you are concerned with having your whereabouts "caught on camera."
  • Lutz Red Gate's .NET Reflector - There's no .NET development without Reflector, I should not even need to mention that I use it. Let's start a campaign to have Reflector bundled with Visual Studio. Update: Reflector was acquired by Red Gate shortly after I wrote this post. I guess they moved quicker than Microsoft and our campaing to have that tool be part of the SDK or Visual Studio is severely at risk.
  • Daemon Tools - Mount ISO images as CD/DVD ROM drives. Update: Apparently I was using a much older version of Daemon Tools and that tool now install spyware even if opt out of installing the stupid toolbar. I'm starting to use Virtual Clone Drive now and it has been alright.
  • Hamachi - VPN made easy as pie. 'Nuff said.
  • Foxit Reader - I can't stand Adobe Acrobloat. Foxit isn't the greatest thing on earth but is good enough and very lightweight.
  • Filezilla - Sooner or later I'll need a FTP client. Filezilla has been good to me.
  • Firebug for Firefox - If there's no .NET development without Reflector, then Firebug is like Reflector for Web development. But I'm sure you already know that.
  • YSlow for Firebug - This nice add-on helps me by suggesting possible ways to improve page loading performance. While you're at it take a look at these other Firebug extensions.
  • 7-zip - Because we all need a shell-integrated compression tool.
  • Tabbed Console - I'm not exactly a command line ninja, but I find myself at the black screen very often. Often enough that it's not rare that I have more than one of those open. The tabbed Console utility allows me to have all my command prompt sessions in the same window. And more than that, I can have flavored command windows tabs, like one for the regular cmd.exe, one for IRb (the Ruby console), one for PowerShell, one for Cygwin, VS Command Prompt, and on, and on.
  • Sysinternals stuff - Sometimes you need to bring the big guns.

What about you? Do you have tools that you feel naked without?