Just 2.3 million lines of Perl and some sticky tape.

July 23, 2008

Laptop Hack: Mute My Sound When I Change Rooms

Filed under: misc — Dave @ 9:40 am

I drag my laptop between different environments pretty often, and it’s a hassle to remember that what was appropriate in the hotel room isn’t always on the plane — you can get your head out of the gutter, I’m mostly concerned that I left music or a movie playing.

Solution:
I created a task (This is all in Vista, but I’ll be upgrading to XP anydaynow, so I’ll verify that it works there) that is triggered on log-on, start-up, lock and unlock that runs “NirCmd mutesysvolume 1″. NirCmd is a little 29kb app that can change things from the command line (the software seems safe after a causal googling, although it’s sometimes included in viruses because it’s useful).

Making a new task is so straightforward I won’t go through it in detail:

  1. Launch Task Scheduler, if you can’t find it, just run “%SystemRoot%\system32\taskschd.msc /s”
  2. Make a new task (Mine lives in the Microsoft folder since I had trouble making a new folder) that triggers on “log-on, start-up, lock and unlock” those are probably your best options
  3. Make an action that “Starts a program” point it to NirCmd with the arguments “mutesysvolume 1″
  4. Save it and you’re good to go.

I was going to include the exported XML of the task, but importing is almost as complex as making it yourself, the paths are hard coded and it also runs my really simple logging batch file for testing “LogSomething mute muting.txt”.

Addendum: LogSomething.bat

@rem Syntax: LogSomething Event File
@echo off
echo %1: ------- >> %2
date /t >> %2
time /t >> %2
echo ----------- >> %2

July 11, 2008

56 Megs for 5 words

Being a Vista user, I’m used to getting smacked in the face, and yet even I was curious when Vista wanted to download a 56 megabyte update — is it installing something completely new?

Massive download

So naturally I checked out the Knowledge base article:

The words “Friendster,” “Klum,” “Nazr,” “Obama,” and “Racicot” are not recognized when you check the spelling in Windows Vista and in Windows Server 2008

Oh, noes! That’s serious indeed. And worse: it applies to such critical applications as Windows Mail! — The Office apps seem to “correctly” accept all of these words.

So to re-iterate, 5 words weighing in at 34 bytes compresses down to 56 megs. Giving a compression factor of ~10^jeeze-louise-people!

Seriously guys, I don’t want to hear any more about how XML adds a lot of overhead.

p.s. I’m pretty sure I know why this happened. The PM in charge of this had two choices: EITHER have a dev write code to do a diff, and get an SDET to test it which could take a long time, and get slagged in the .01% of cases where something goes wrong OR just throw resources at it, in this case the bandwidth of millions of people. It might have actually been the right choice from their perspective, but it betrays some poor design somewhere.

p.p.s. Standard disclaimer: I used to work for the Borg as a PM, but I know nothing about this particular team.

July 10, 2008

Using AWK to convert CSV to XML

Filed under: awk, programming — Dave @ 10:52 am

I needed to convert CSVs to XML, so it’s time to return to my text processing hero: AWK.

CSV to XML gets me 90% of the way there, except, it doesn’t actually convert from Comma Separated Values to XML, it uses space to separate values. Updated script:

BEGIN {RS = "\n"
FS = "," }
NR == 1 {for (i = 1; i <=NF; i++)
tag[i]=$i
print "<" node "XML>“}
NR != 1 {print ” <" node ">”
for (i = 1; i <= NF; i++)
print " <" tag[i] ">” $i “
print ” “}
END {print ““}

Notes on cleaning your data:

  • our column headings need to be sane, ie: no spaces or weird characters

  • Numbers with commas, ie “12,231″ won’t work