Apr 23

Just over a year ago, I spilled coffee on my keyboard at work. Almost entire left side of the keyboard was ruined. The buttons had become sticky from the mocha and were acting stubborn. I replaced it with a new ergonomic keyboard. Life was good.

In the meanwhile, I built a cheap computer at home. Instead of buying a new keyboard, I decided to clean the coffee on my old keyboard at work and put it to use with my home computer. Most of the keys work fine after cleaning. I don’t end up using the keyboard at home as much as I do at work, so things are working pretty well.

That was until the past Monday. On Monday, I found that one - just one - key on the new (well, not so new anymore, but comparitively) keyboard at work is being insensitive. That key had to be the colon (:) key! As a Vim user, that spells trouble.

I am OK using the almost 50% ruined keyboard at home. But using an otherwise perfect keyboard with just an insesitive colon is proving to be a big pain in the… oh boy… no pun intended what-so-ever!

But then again, at least it is not the <ESC> key!

Apr 15

There’s been a lot of people on the blogosphere reporting shell history. The idea is to know what kind of commands different people use on their shell - kinda geeky, but none the less. Here’s the command most are using:

  history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

A Perl enthusiast that I am, I started out to do the same in Perl instead of awk. I started writing a script hotlist that will get the shell history, count unique commands and sort them in descending order of the count. Seems very straightforward. Turns out, its only straightforward - without the very.

Since history is a built-in shell command, it cannot called it with the qx// or back-tick (``) syntax of Perl to fetch shell history. I resorted to Google to find a solution, but could not find one easily. After some help from clpm, I came up with this:

#!/usr/bin/perl

use strict;
use warnings;

my %hist = ();
my @hist;

$hist{(split /\s+/)[3]}++
  foreach ((-p STDIN) ? <STDIN> : `$ENV{'SHELL'} -c history`);

print map {"$hist{$_} : $_\n"}
        sort {$hist{$b} <=> $hist{$a}}
          keys %hist;

To use shell’s built-in commands, you must invoke the shell and have it execute the built-in command. In the above script, that is done with `$ENV{'SHELL'} -c history`, which in my case expands to `/usr/local/bin/tcsh -c history` since I use t-shell. The shell can be invoked by qx// or back-tick (``) to collect the output.

You can use this script in two flavors:

  % hotlist
  % history | hotlist

The first flavor starts a new shell and calls the history command in it. So you get the information from saved shell history. It does not contain commands form the active shell. If you want to include the active shell too, use the second flavor. Where you pipe the current shell’s history into the script.

Hopefully, this will help the next person who wants to use shell built-in commands in Perl. Like I said, I am a Perl enthusiast, not an expert, so this may not be the best solution.

I am sure some Perl guru will manage to cram all that in a one-liner, but that was not my intent.

Apr 13

This is very impressive. With Vimpress, you can publish/edit WordPress blog posts from within Vim, like I am doing now. It works great too. This brings together my favorite editor and my favorite blogging platform… Its been around for a while, I only found out today!

UPDATE:

I did find that the plugin does not play well in Vim compiled with python disabled. Vim throws a lot of errors when loading the vimpress plugin (blog.vim file). Adding the following lines before the command! lines in blog.vim addresses this:

if !has("python")
  finish
endif

Cheers!

Apr 09

Is it just me? Or others are getting too many Oops! messages from Google websites lately?

I got this one from the Gmail

Gmail Oops! - Click for full size

Gmail Oops! message after archiving a message

And this one from Google Calendar

Google Calendar Oops! - Click for full size

Google Calendar Oops! message after creating a new event

… more than a few times today. Almost a 5-10 times everyday in the last few days, combined on all Google sites I use.