Thursday, October 18, 2007

Learning Perl

Perl makes quick programming very easy and more elaborate things possible. It is an exceptionally flexible, easy to grow into language with an outstanding group of people using it. The Perl Community is every bit as exceptional as perl itself.

Even if you've never written a program, or if your programming experience is restricted to things like DOS batch, perl is something you can learn. If you wish you could just "hack things" when you need them, perl is a great choice.

So, how do you get started? Well, there are a lot of resources out there, some better than others. I would suggest you start with this site, which offers a nice variety of options, and that you fire up an IRC client and join us in #perl on irc.freenode.net for more interactive advice and encouragement.

I'll be looking for you.

Labels:

Undoing INSERT COIN and Related Ideas

YOU CAN FIND THE ORIGINAL POST HERE.


Wow. This post has seen more than 50,000 hits in less than two days (UPDATE: it has now exceeded 110,000 in three days). To say that it was unexpected is completely insufficient to describe my reaction. In any case, thanks for sharing my fun. And that's exactly what this is meant to be, fun. Not malicious, not mean-spirited, not damaging in any way. Almost all the comments I have received reflect that spirit. There are a few, however than don't make me smile (and didn't make the comments page).


Un-"hacked", and READY


First, if you came here because you were "hacked" there is an easy solution. Power-cycle your printer. That is, turn it off, wait a few seconds, turn it on. The program uses a documented, supported feature of HP's product to do something very ephemeral and undoing it is as easy as a restart.

Second, please have fun but think before you act. If it is against the culture of your office enviroment to have this sort of fun, consider not trying. You will be the only one having fun. More serious may be a violation of your company's Acceptable Use Policy which could get you in real trouble.

So, please, practice "safe hacking" and use your entire brain when choosing how to use this information.

Have fun.

Labels: ,

Tuesday, October 16, 2007

Get the Weather on your HP 4200

I mentioned, here, that I wrote a program to put the weather on the HP 4200 in our office. The program uses the perl Geo::METAR module to parse METAR weather information from NOAA. You'll need to install the module if you don't already have it (and you probably don't). Install it using ActiveState's PPM for Windows and the CPAN program (or OS package manager) for everything else. You will also need to know your ICAO airport code and the IP address of your printer.


How does it know?


You can use some sort of cron job or the Windows "at" service to run it periodically. The METAR data doesn't actually change more than once an hour so more frequent updates won't buy more accuracy. This program requires a little more assembly than the earlier one but the comments in the source should be sufficient. The code itself was a 10-minute hack and is not intended to be lovely, but it has performed flawlessly for years now. The program targets the HP 4200 but it is very possible that it will work with other large display printers as well—it can certainly be modified to do so.

I like this one because it is hackish and useful at the same time.

NOTE: Windows users installing Geo::METAR via PPM may find that the temperature variables need to be edited. If you get errors you can try making them C_TEMP and F_TEMP. I haven't tracked down why this is true, but it appears to be.

Labels: ,

Using Perl with Windows

It appears that a lot of people don't have any idea how to run a perl program under Windows. Perl runs just about anywhere and Windows is no exception. The easiest way, and the way I recommend, is to download ActiveState's free Windows Perl distribution. It is very friendly with a nice installer. Once you have it installed, the program in this post will run fine.

While you are at it, download a copy of the free Komodo Edit code editor. I have been using it a lot lately and really liking it. It is responsive and has a nice feature set. Since it provides background syntax checking and tool tips with syntax it actually makes learning perl easier. It understands quite a few file formats, so it is good for more than perl.

Labels: ,

INSERT COIN

PLEASE READ THIS BEFORE USING THE PROGRAM (or if you are not amused)


Can this silliness be used for good? Perhaps...


It is amazing how unaware some people can be. This little perl program allows you to set the "Ready Message" on HP printers to whatever you'd like. (if you want to run it under Windows, and don't know how, read this.) I wrote it after coming across the command in an HPPJL (HP Printer Job Language) reference manual I was reading for some reason that I now forget. Thanks to the flexibility and power of perl, it was a no-brainer to play with the new information. (Maybe you should consider learning perl?)



I want my ready back!


Well, of course I couldn't ignore such an opportunity, and it turns out to be a lot of fun. You can think up your own funny, confusing or scary messages. My personal favorite is "INSERT COIN" which fits perfectly on the small LCDs. You can even sit in sight of the printer and change the message while watching the reaction of your victim (or reading about it). Don't be surprised, though, if a large fraction don't even notice. I was quite surprised myself but, it appears, some people don't look at what is in front of them.

I wrote a more elaborate version that takes advantage of the HP 4200's larger, four-line display. It sends the current weather conditions which I grab from NOAA using the perl Geo::METAR module. It updates every 10 minutes. Amazingly, while many people noticed the report on the printer display, no one questioned it!

People are endlessly surprising. Isn't it great?

NOTE: There have been many requests for help with this. Non-networked printers, running the script, etc. While I cannot guarantee anything, you might find help on FreeNode's #perl IRC channel, here. In about three days this post has garnered more than 105,000 unique visitors. If a few of you can lurk there and help out it would be great. Apparently many of us share a sense of humor. Maybe there is an "INSERT COIN" community. Who knows?

A Philosophical Comment


The anonymous comment below, accusing me of considering myself "king of the hacker elite" made me re-read this post. I originally thought he was responding to a comment I made, not the post itself. After thinking about it I realized he might not have read any of the comments at all. That being the case, let me be very clear about something: while I definitely enjoy being extremely extroverted in my attention, and noticing all sorts of details and peculiarities in the world around me, I do not believe that such a tendency is exclusively meritorious or inherently superior. I work with many people who do not share this cognitive style but are intelligent, insightful people who have taught me a lot. Please don't take the observations above as belittling people who don't share my natural fascination with the things in the world. That would be much different than my intention.

Labels: , , ,