Saturday, 28 July 2007

Perl's zipping operator

Every self-respecting dynamic language has a zipping function (or method). Python has its built-in zip(), haskell as well. Ruby gets it implemented as one of Array methods. I just didn't know (untill 3 days ago), that it's particularly useful for perl programers. Unfortunately, its name is THREE CHARACTERS LONG! O_o, that is waaay too many. That's why Larry Wall introduced zipping operator. You wonder what is it? Isn't that obvois? It's Yen symbol! Come on, it looks like a zipper anyway!

Genius.

Except for the fact, that there are _two_ Yen signs in unicode (¥ and ￥). And only one is recognised by the parser. Lame. Fortunately, Larry changes it to 'Z' in perl 6

Visual Basic AndAlso short circuit operators

Well, story is simple. When Visual Basic was designed, either no one knew about short circuit operators, or they didn't recognise their virtues. And years after, they couldn't stick it in because of backwards complatibility. But they found a solution eventually: AndAlso and OrElse operators. Simple, isn't it? AndAlso it doesn't break the compatibility. I only wonder why OrElse is OrElse and not... let's say OrPossibly or OrMaybe or OrHowAbout.

Thursday, 12 July 2007

The reason

I had to switch to windows for some time and, after working under ubuntu for over a year, I finally realized what linux users meant when saying that win wasn't userfriendly. Linux' great power comes from its extensibility (obviously) and customizability. The poor support for the latter drives me mad every time I need to use win. It took me couple of days to set up a usable and useful console, so hereby I include the recipe.

Tabs and good look

Since being console under windows means running in one, to get a tabbed view we need to download a wrapper. Its name is, surprisingly, Console and the tabs feature is enabled in latest versions (Console2 has it, while 1.5 not. if you download the latest version (>2.0.131), you will get multiple shell support as well). There's no need to install. Just extract, run the Console.exe, et voila. Much prettier, isn't it. It is a good idea to put the folder in some appropriate place (like c:\Program Files\Console2).

Shell

Next thing we're gonna need is Powershell. I still haven't dicovered all its features, but tab completion, automatic slash-to-backslash convertion and aliases to many bash commands (including man and ls, yipeee!) makes it good enough for me. You can download it from microsoft's site. To get Console running with powershell you can use its options window (Edit/Settings...).

Multiple shell support

Console can use multiple shells. How does it work? Say, you prefer using powershell, but it's not fast enough for your machine. Or you use apps with command line interface quite often (python, mysql, irb). Here's how you can get Console to use all of them: open the console.xml file in your console dir, and find the <tabs> tag. Every tag is a preset for a type of console to open. There is only one <tab>...</tab> entry now. Duplicate it, and edit the shell attribute in the <console> inner tag. Here's what the section may look like afterwards:

Keyboard shortcuts

You get by default shortcuts Ctrl+F1, Ctrl+F2, etc. for shells you set. It's customizable (obviously). It is a useful trick to define hotkeys for launching Console, so that you can run it whatever window is active. There are plenty of hotkeys deamons for win, that let you do that. I'm using Hot Keys Plus