Image of the glider from the Game of Life by John Conway
Skip to content

My First Irssi Script- Binary Timestamps

A couple nights ago, while on Freenode, lilo (Rob Levin) posted a small log of a chat in the channel, and I noticed that he was using the Unix Epoch time as his timestamp in his IRC client irssi. I thought that was genious, so I set out to code an irssi script that shows binary timestamps. Seeing as though I am still relatively new to Perl, I knew this would be a challenge, but I figured it wasn't too difficult to handle. So today, I set out to code such a script.

The first thing for me, again, because of my n00b skills, was to create a stand-alone program that converted the system time to a binary string representation. I wanted to test and retest that the conversion worked perfectly before testing it in irssi and crashing the program.

So here was what I had in mind:

  1. Get the hours and minutes from the localtime on the system.
  2. Convert the hours to a binary string.
  3. Convert the minuts to a binary string.
  4. Concatenate the binary strings together with the colon time seperator.
  5. Store the concatention in the irssi timestamp variable.

The first four steps took no time at all. I could print them to the console and see the results. The wall that I hit was trying to hook it into irssi. I had no idea where to begin with that. So I figured I'd start looking at other scripts, and figure out exactly how to do it. There was also documentation on the irssi web site for creating brief scripts. Needless to say, it isn't that comprhensive, and I spend more time hacking than learning. I can easily say that learning the syntax and functions took 80% of the time getting this script finished.

Well, it's finished. It's a fairly easy and brief script. Nothing to it really. You can download the whole script here. To execute the script, just /script load and to unload the script, just /script unload binary_time. I would be interested in feedback on the script, if you wouldn't mind testing it out.

Also, I received a couple emails and a comment on the last post regarding my hacked madcow theme, and if I could post it here. Sure, no problem. Here you go.

{ 3 } Comments

  1. HarleyPig | August 28, 2006 at 7:23 am | Permalink

    I don't mean to demean your hard work, but you made it too difficult.

    You can get rid of the hour2bin and min2bin subroutines and replace them with the following in the convert_to_binary subroutine:

    my $new_time = sprintf "%05b:%06b", ( localtime )[2,1];

    And I *never* thought about changing the timestamp format like that, just using the simple MM/DD/YY HH:MM in it's various incarnations. Now that I have the thought in my head I'm thinking of all *kinds* of fun things I can do ...

  2. Aaron | August 28, 2006 at 10:53 am | Permalink

    Hehe. Goes to show my inferior n00b skillz when it comes to Perl. I knew there had to be a simple way, I just didn't know how. Oh well, on an updated release, I'll chop it down to the sprintf.

    I admit though that now that I know how to hook the Perl scripts in Irssi, I am coming up with all sorts of fun things that I can do. 🙂

  3. HarleyPig | August 30, 2006 at 9:52 am | Permalink

    With bitlbee and jabber you can have all kinds of connectivity. And irssi can be setup as a proxy so that you can attach to it from anywhere and have access to your personal setup.

Post a Comment

Your email is never published nor shared.