Category Archives: Scripting

Explorer Here

Command Prompt Here seems to be a well-known feature among the Windows users. It lets you right-click on a folder and open a command prompt with the current working directory set to that folder.

But what about its “functional inverse”, i.e., start an explorer to explore the current directory? Well, you can execute explorer . in the Command Prompt, but that will not be exactly “correct” since the tree view of folders is missing. Apparently you have to add a completely obscure argument… I put this command in a batch file on my path:

start "" explorer /e, .

Note that there cannot be a space between the “e” and the comma. Don’t ask.

Higher Order Perl

I find this recent book (sort of available online) by Mark Jason Dominus to be very CS-friendly. The reason: Closures!

The Perl Review: Why did you write Higher Order Perl?

Mark Jason Dominus: [...] But I had a few hidden agenda items as well. The book is about how to use closures, and I think there are too many languages around that have no easy way to use closures. Java, in particular, seems to me to be a giant step back towards the languages of the 1970s.

Two interesting tidbits from the book are:

  • The term memoization was coined in 1968 by Donald Michie.
  • Data marshalling is so named because it was first studied in 1962 by Edward Waite Marshall, then with the General Electric corporation.

In a previous job, I have done a lot of programming that involves data marshalling, now the term finally makes sense!

Sysinternals PsTools

PsTools from Sysinternals is a collection of command line utilities that let you manipulate processes in Windows. Among the tools, I personally use pslist and pskill every single day(*). Check it out!

And if you have pslist, then put the following into a batch file, say mlist.bat. It’s very handy for nailing down memory leaks. (Note that the @ sign in the front of a command in a batch file suppresses the echoing of the command. That’s why many batch files start with @echo off.)

@pslist | sort -n +5 | tail -n 10

BTW, with the release of Windows XP and Windows Server 2003, Microsoft has bundled two command line tools that do similar things (tasklist and taskkill). However, their command line interface is awkward. I recommend you forget about them and stick with PsTools.

(*) largely because of Firefox and Acrobat

All but the first few lines of a file

You would think that there must be a utility in Unix like head or tail that would chop off the first few lines of a file and output the rest. Well, I haven’t found it yet.

In any case, perl worked.

cat foo.txt | perl -e "print splice @{[<>]}, 5"

Perl Regular Expression Matching is NP-Hard

Do you know that Perl “regular expressions” can accept NP-complete languages?

Happy backtracking!