Groundhog Day Plan

November 18th, 2008 10:41 AM by Luke Maciak

A while ago we talked about surviving a zombie outbreak. While zombie events are not only very rare but also completely fictional, it does not hurt to have a plan just in case they happen. As it turned out, quire a few people gave this some thought and were able to discuss different strategies. Today I wanted to talk about one of these other rare, unlikely and fictional events: a repetitive time loop just like the one seen in the movie Groundhog Day.

groundhog_day.jpg

If you haven’t seen this movie, do yourself a favor and go watch it now. Or this weekend with your loved one, your kids or your family. Then come back and join the discussion. Let’s establish some sort of a framework we are working with. First, we do not know why time loops happen. Second, we know that each loop has an exit condition of some sort. The loop in the movie terminated when Bill Murray’s character stopped being a self centered ass and actually started caring about the people around him. Your exit condition may be different though.

It is probably safe to assume that a time loop, being a very subjective experience may be tied to some personality flaw or personal condition of yours. Maybe you need to become a nicer person. Maybe your loop terminates when you finally overcome that paralyzing fear of heights. Perhaps your loop is tied to your fear of commitment. Whatever it is, you can probably assume it has something to do with self improvement or personal growth of some sort. It is not something you can accidentally stumble upon, or fake. Unfortunately it is impossible to tell exactly what will trigger loop termination while inside of it. The general census is that any attempts to better yourself is probably taking you closer to the end condition. What will trigger it however, must be found through experimentation. Good news is that you have all the time in the world to figure it out.

We also know few other things about these loops. First and foremost, you are virtually immortal. You cannot terminate the loop by suicide, or accidental death. Dying will simply end the current loop iteration, and immediately start the next one.

An average loop iteration usually starts with you waking up in the morning. The duration of the iteration will usually be 24 hours, but it may be less. If you decide to stay up for that whole time, you will still wake up once the iteration ends. You will still start the iteration in your bed (or wherever you were when the loop started) no matter where in the world you are when the iteration ends. It is unclear whether or not you will feel the physical fatigue in the morning. It is possible that you will wake up feeling the same way you felt when the loop started. So if you had a good nights sleep, you will feel rested. If you only caught few hours of sleep, you will feel tired. I’m basing this observation on the fact that even if your physical body is somehow destroyed (burned, crushed, mutilated) you still start each loop iteration intact. So I’m guessing that your body is restored to the exact quantum state it was in when the loop has started, with the exception of your memories which are carried over somehow.

Keeping track of time within a loop can be tricky. You can’t use a calendar or notches on the wall to track the passage of days. You could try remembering which day it is but it could easily get confusing. Especially after you got into 3 digit numbers. So you need something more permanent. In the original Groundhog Day script the main character kept track of time by reading a page in a book each day which seems like a good idea, unless you are an avid reader and you would like to read more than that. Still, you could set your limit to be 20 or 30 pages a day, or whatever you are comfortable with and keep track this way. Of course if you are reading books out of order (ie. the interesting ones, rather than systematically working your way from A to Z) it could get confusing too. Anyone has an idea for a good time tracking solution which would work within a loop with some degree of accuracy?

How far can you travel? This question always comes up in the Groundhog Day discussions and I’m not sure if I know the answer. In the movie Bill Murray’s character is trapped in the town by a snow blizzard and road closings. This seems to be by design, since the friendly small town atmosphere is conducive to accomplishing his self improvement goal. I’m not sure if this would be a defining characteristic of every loop. My guess is that if your location is somehow significant to the end condition you may not be able to travel far. Which is not necessarily a bad thing since it narrows down the number of variables you need to work with and gives you a hint as to how to terminate the loop. If you cannot leave, then you know you have to work with what you have around you.

However, some loops may not be localized. In such case you could theoretically jump on a plane and get to many interesting places in the world with few hours to spare for sight seeing, or sampling the local cuisine. Of course if you commit yourself to spending 6 hours on a plane to spend few hours in Europe you are not really working on your self improvement goal. Which brings me to the fun part: diversions.

As we established, arriving at the end condition will be long and arduous process. It may take you years, or even centuries to accomplish. In the meantime, you are immortal and your actions have no permanent consequences while you are looping. Every morning you start with a clean slate. This means you are free to do anything you want. Needless to say, before you start working on self improvement, you will probably do all kinds of stupid shit that you would never do in other circumstances. For example, you can max out all your credit cards on stupid shit, quit your job, jump out of a plane without a parachute and etc. Depending on your personality you may really take advantage of this freedom, and go wild. But we probably don’t want to talk about fulfilling your primal urges or some dark desires here. This stuff will get old real fast anyway.

There will be a long stretch of time between the time you get fed up with doing crazy stuff for cheap thrills, and the time you get out of the loop. Months, maybe years if not longer. You will have to find some constructive hobbies to keep yourself occupied. Otherwise you might go crazy before you get out. So what long term projects or activities would you use as diversions. The main character of the Groundhog Day used this time to learn to play a piano, and read a lot of poetry and classics. Given virtually infinite amount of time, what would you do?

I’d definitely do some reading. There is a small public library in a walking distance from my house, and a huge, well stocked Barnes & Noble store so I don’t think obtaining books would be a problem. The only inconvenient part is the need to fetch the book back each day day as it will disappear from your house every morning.

I’m not sure about playing an instrument. My musical sense is not that keen and I never had a particular desire to play/create music. Also I don’t own any instruments, and don’t know any good teachers. There is a Guitar Store shop nearby though so I could probably learn that at some point but I’d probably put it on the very bottom of my list.

I’d love to learn a new language - preferably Japanese. And no, it’s not just so that I could watch Anime without subtitles or play imported games but it would be a factor. I’m already bilingual, and speak and write fluently in both English and Polish. I also studied German and Russian but I forgot almost everything about these two languages. The thing is, the Asian languages are so structurally different that it would probably be an interesting and mid opening experience.

I’d try to learn new programming languages and improve my coding skills and generally broaden my knowledge. Since I might be stuck in that loop for centuries I wouldn’t want to get rusty. The problem is that I would not be able to retain any of my work between loop iterations so working on large, time consuming projects would probably be out of question. I’d probably stick to small, solvable problem sets or exercises that could be completed within few hours. I’d probably blow through the whole Project Euler problem set multiple times, with different languages and using different approaches and paradigms. Maybe I could even get a jump start on my PHD. I wouldn’t be able to attend lectures or write a thesis of course but I could possibly learn about the curiculum, the required readings and start going over the required readings and I could probably find professors willing to answer some of my questions and coach me through the difficult parts. It would be a one time favor, every time.

Playing video games would be a problem because I wouldn’t be able to save. I’m usually not the kind of person who plays the game through multiple times. I play it once usually, unless the game offers very rich repeatable experience. So I’d probably try to speed run the games. I’d get them first thing in the morning and then play them till I beat them, or run out of time. Depending on the length of the game this would be like an all day affair so I wouldn’t do that every day. Just some.

What would you do? Let me know in the comments!

On WoW and MMO Questing Paradigm

November 17th, 2008 11:34 AM by Luke Maciak

Hey, have you heard about that world. That world of war and craft? Yeah, I’m sick of that world. I’m getting out. I seriously haven’t launched WoW in probably over a month now and I feel no urge to. I think my adventure with that game is over. Damn it, I’m an antisocial beast. I have no clue what made me think I could play a game populated by millions of other human beings and not wish they would all die and rot in hell, and get the fuck of my game. I mean there were times I had fun teaming up with other people but usually I was just hoping that all these friendly people just fuck off.

Often if someone wanted to talk to me I would pretend that I didn’t speak Orkish and just type stuff in the Troll language, then use the /confused emote when they responded, wave, bow and run off to do my thing. I’m being social at work, then I come home and I’m being social with my family, and then I sit down at my desk to be social with some random assholes in WoW? I think not. My brain gets totally pissed off if it doesn’t get it’s daily quota of sweet solitude. It was plain to see that I was not getting all out of WoW because my general dislike of chatty online strangers who want to team up and run instances all the time. If you take the social aspect out of WoW the game essentially turns into a Diablo like running game that involves running around and killing things. There are some plesant diversions such as collectibles, minigames, achievements and etc. But in the end, your daily grind usually boils down too running from one area to the other and killing X of Y. There is nothing wrong with that, but I have been spoiled by RPG games with real depth to them.

You know, games which will actually allow you to play a thief and level up by stealing, fencing and trading, without really needing to commit any bloodshed. I’m talking about Morrowind of course - that one game that keeps drawing me back in over and over again due to it’s immense replay value. The great thing about Morrowind is the sheer variety of quests you will get just by doing side missions unrelated to the main storyline. One day you are spying on someone, next day you are stealing secret documents, later you are sent to negotiate trade agreement and etc.. You can easily level up and advance your character without ever needing to kill anything.

Yes, you can play a pacifist in WoW too but it is not easy. It is actually quite difficult, if not impossible to achieve without serious commitment to the cause. If you are doing it, you might as well start a blog about it and people will read it because it is such an unusual (and strangely awesome) thing to do. In games such as Morrowind and Oblivion, a semi-pacifistic life style can simply a logical outcome of you choosing your character class. If you rolled a thief or a rogue you will be doing missions that require stealth, good speechcraft and security skills (stealing, extortion, burglary, pick pocketing) rather than the heavily combat oriented stuff. And there is nothing unusual or blog-worthy in that. It’s just how that game works.

Part of it is of course the fact that Morrowind and Oblivion have fairly complex system of rules that allow you to train in pick-pocketing, or lock picking and then use these skills in the game. This complex system of attributes, skills, racial/class feats and special abilities is the legacy of the western single player RPG tradition. Computer RPG games inherited it from pen and paper games like D&D which (out of necessity) had to include rules for all this non combat stuff.

Funny thing is that MMO’s break with this tradition. If you are a gamer you know that this is true. And yet someone looking from the outside would be surprised. D&D is social affair isn’t it? You get together with bunch of friends, you drink a gallon of Mountain Dew, eat a bag of Doritos an tell inappropriate jokes while the GM is trying to build tension or whatever. You could almost say that D&D is a multi-player game, could you not? WoW is a multi-player game too. Massively! Sounds like a match too me. But it’s not. Playing WoW is probably as far from playing an actual pen & paper game as you can get. In WoW your stats are limited to bare bones minimum that is required for calculating how hard your character can hit stuff. When you level up, you get almost no choice as to how you can upgrade your character. The skills you learn are mostly special attacks of varying range and/or damage output. You can’t learn lock picking in this game because there are no locks to pick. You can’t use your superior charisma or speachcraft skill to talk your way out of sticky situations because you never actually talk to anyone in this game. Your interaction with NPC’s is limited to taking or turning in quests and not much more.

WoW does have a limited crafting system but you can’t just play a craftsman. In order to excel at your craft (be it smiting, engineering or leather working) you need to go out and kill large quantities of “things” to gain the necessary levels and XP. The crafting system is meant to be a diversion you engage in between missions. The kill X of Y thing seems to be a MMO thing rather than a WoW thing though. It is like a MMO questing paradigm that almost defines the genre.

Is it always like that though? Are there MMO games out there that do not follow this pattern and offer you alternate ways to advance? I know of two counter examples. One of them is Eve Online which I have tried and got bored with pretty quickly. But then again I wouldn’t really call Eve a conventional MMO. I’d probably classify it as a hybrid between Microsoft Excel and Progress Quest - the only other game I can think of, that rewards you for not playing it. But that’s just my opinion and you have to keep in mind that I’m a people hating introvert and when I play MMO’s I actually run away from people that want to team up with me more often than not. If you are a social person, Eve like any other MMO offers you tons of entertainment in the form of guilds (or corporations) and player driven drama.

The other game that used an approach that was closer to single-player games (and thus the pen & paper roots) was Star Wars Galaxies where you used to be able to pick a merchant or an exotic dancer as a class. I never played that game, but I heard both good and bad things about it. All I know is that at some point they decided to overhaul the whole game engine and nerfed it down to the point where it became almost a WoW clone.

Everything else seems to follow the WoW lead, simplifying the stats and game mechanics to the bare bones minimum, and reducing the game play down to a controlled genocide. I can see why this is happening. The “kill X of Y” type missions are easy to write, script and deploy (so you can make them in bulk). Players can easily team up and accomplish these missions together as a team, and the missions are easily repeatable (ie. large mobs do not deplete easily, so players are not sitting around waiting for them to re-spawn all the time). But I can’t help to think that the MMO genre would be richer and deeper if it went back to it’s roots, and added bit more complexity to it’s system in order to allow for some more variety. But that’s me.

Revisiting Serenity

November 14th, 2008 11:30 AM by Luke Maciak

As you may, or may not know I have been watching Firefly lately. Actually, watching is the wrong word here. I have been savoring them. Normally when I find a show that I really like I gorge on it like an uncivilized beast. I plunge myself into the show, and watch 4-5 episodes per day forsaking sleep and other worldly pleasures such as my video games, side projects and scouring my collection of RSS feeds for funny pictures and quotes to put on /dev/random. I immerse myself wholly in that show until I run out of episodes.

But with Firefly it was different. I knew from the start that I only had 14 episodes to work with. So I paced myself. I took my time. I fell in love with the Firefly universe! I fell in love with the characters! And I enjoyed every second of this wonderful show.

Once I was done I could not believe there was no more episodes. I wanted more! I needed more! It was unfair. And then I remembered about the movie. Since the first and last time I have seen it was two years ago I decided to revisit it. I wanted to see how the movie ties into the series while I still had it fresh in my memory.

serenity.jpg

When I saw the movie for the first time I loved it. It had a unique setting, it was funny, sad and moving. It had all the right parts, a good story, snappy dialogs and interesting characters. I was hooked.

Watching it the second time, as a fledgling browncoat I saw it very differently. It seemed a rushed, haphazard attempt to tie all the loose ends from the series as well as introduce new viewers to the universe, the crew and the mystery of the series. It failed to captivate me the way the series did. It had the same characters, the same universe but the magic was somehow gone. The pacing with which Firefly would build the tension up and intersperse it with humor was off. It did not flow the right way. And I think I understand why.

When Joss Whedon scored the movie deal he had a choice to either shoot a big budget, 2 hour episode of Firefly that resolves nothing or neatly wrap up the series and give the fans some closure. He obviously opted for the later and I don’t blame him for it. But as it turns out, 2 hours is hardly enough time to say everything Whedon wanted to say. Some compromises had to be made and some loose ends had to remain untied. Others could not be given the time they deserved. If you are a fan (even new one like me) this will eat at you.

Let me give you some examples. In Serenity the slow cooking mystery of River’s past is condensed and compressed into a palpable form comprehensible to first time viewers. It seems rushed and uninspired. Firefly was very subtle about dropping hints about Rivers past. For example you don’t start seeing the “Blue Sun” company logo everywhere until your second or third viewing. That’s when you make the connection between it and the Academy where River was held, and the “Hands of Blue” men who pursue her. All of a sudden you understand why she was ripping off the Blue Sun labels of the cans in the mess hall, or why she attacked Jayne who was wearing a Blue Sun t-shirt.

In Serenity the all present Blue Sun company is marginalized. The mysterious and sinister “Hands of Blue” men are gone - completely ignored without even a mention. River’s origin story is explained in the first 15 minutes in a lengthy exposition/flashback scene. I don’t know about you but I liked the subtlety and mystery. This direct, up-front approach worked great when I didn’t know anything about the series. But on the second viewing of the movie it was quite shocking. It almost seems like a retcon too - since Simon manages to have a lengthy conversation about River’s condition with the head doctor before he springs her out. Hmm…

Similar thing happens to the Reavers. In the series they are a complete mystery. We can see their ships, and the carnage they leave behind but they are never shown on the screen. They are a huge unknown and most people seriously doubt their existence. Simon for example considered them to be a myth before he joined the crew of Serenity. No one knows where they came from, or where will they strike next. That’s what made them scary. I remember a scene from the show when Serenity is passing a lonely Reaver ship in space and everyone on board is pretty much holding their breath hoping they won’t pursue them. Just seeing their ship pass in a distance was a tense moment for the crew.

In the movie their origins are explained and they get plenty of screen time. In fact, you see bunch of them straight away in the first act. Furthermore, they are portrayed as mindless zombie like beasts - disposable cannon fodder to be hurled at the heroes by truckload. Mal and the crew kill so many of them in the 2 hours you literally lose count. Furthermore they graduate from a myth to a known and persistent danger. For example Wash and Zoe somehow know about certain areas in space where they tend to congregate. Its a huge change, and IMHO for worse! I much preferred the mysterious and scary Reavers that you run away from, than the mindless, zombie like Reavers you shoot en masse.

Serenity also introduces real copout supporting characters. Mr. Universe for example should be called Mr. Plot Device. When I originally saw the movie assumed that he was one of those corny, obligatory hax0r characters that every series introduces sooner or later. It seemed plausible at the time that there crew of Serenity would have worked with this walking stereotype and reusing him to play a key role in the movie was a clever move by Joss Whedon. Upon revisiting the movie I realized that I gave him more credit he deserved. Mr. Universe was obviously a blatant plot device character - introduced just so that the crew had access to a pirate broadcasting station. It’s a very heavy handed move and possibly the weakest part of the movie.

And of course there are the deaths. I know that in Whedon’s shows main characters often die. There is a difference though between a dramatic and meaningful death scene and a gratuitous one. IMHO, Wash died needlessly. It was just so… Random and uncalled for. Yes, life is random and unfair as well but I felt that there was just nothing to accomplish there by killing him off. It was not a dignified death. Not a heroic death. It was pretty much an accident.

Whedon tried to kill two birds with one stone. He aimed to create a good standalone movie that could be successful in theaters. One that would tell a complete story, with a begging and an end that would be accessible to people who have never seen the series. In that he succeed. He also tried to appease the fans of the show, and write a fitting ending they could live with. It was a good attempt but it fell short of the mark. Due to the various compromises, shortcuts and omissions it fares well as a stand-alone film but it just doesn’t live up to the high standards set by the series and fan expectations.

The worst part is that the movie definitively rules out a possibility for the series to be ever renewed. The story has been told, the mysteries have been resolved (or hand waved away and brushed under the carpet) and crucial characters have been killed. The Firefly saga has been wrapped up and closed forever. I almost wish this movie was never made. This way I could have kept hoping for another season or two - and an ending that was not rushed and simplified for new viewers. But alas, if there was no Serenity movie I would probably never get into Firefly and that would probably be even worse.

Email Signatures… 5 Lines or Less!

November 13th, 2008 10:52 AM by Luke Maciak

I really think that Microsoft needs to include a new “feature” in Outlook which would restrict email signature to at most 5 lines of text. You really do not need more than that to list your name, job title, company and phone numbers. Some people go totally overboard with these things. Recently I found this gem in my inbox which managed to hit just about every single point on my do-not email signature list. Names and any other identifying information was changed to protect the stupids:

John Smith
Look at My Awesome Job Title Here

Company Name
~”Company Motto”~
[company logo image]
1234 Some Street
Some Stupid Town, NJ 00001

Contact Information:
****************************
Office Phone: (999) 999-9999 x1234
Cell Phone: (999) 999-999
Fax (999) 999-9999
Email: jsmith@companyname.com
****************************
****************************
_____________________________________________________________
##############################################
##############################################

This message originated from the Internet. Its originator may or
may not be who they claim to be and the information contained in
the message and any attachments may or may not be accurate.
##############################################
##############################################
_____________________________________________________________
##############################################

This E-mail is confidential. It may also be legally privileged. If
you are not the addressee you may not copy, forward, disclose or
use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return E-mail.
##############################################
_____________________________________________________________
##############################################

Internet communications cannot be guaranteed to be timely, secure,
error or virus-free. The sender does not accept liability for any
errors or omissions.
##############################################
______________________________________________________________
SAVE PAPER - THINK BEFORE YOU PRINT!

Keep in mind this was all done in dark blue 18 point font. The image logo is huge and weighs in at more than 1MB making the email seem much bigger than it really is each time. The legal notice and all the ASCII art around it is actually bolded for no god damned reason!

I’m going to ignore the fact that the legalese is there because this guy wanted it. I understand when people are forced to include these pointless things in their email by pointy haired individuals in power. I however know for a fact that this guy’s company had no explicit policy regarding legal disclaimers in the email. You can probably see that his disclaimer is generic - he probably found it somewhere on the internet and quickly pasted it into his email signature field because it looked empty. Sigh.. I seriously think there is some competition going on out in the business world to have the longest, most retarded signature. There are probably cash prizes, and the winner receives the award during a formal function sponsored by all the major corporations. They probably televise it too on like E! or some other bullshit channel like that - I just don’t know about it because you couldn’t pay me to tune into these networks.

Let’s get back to the signature at hand though. IMHO, The last line is the best. Bold, humongous heading that overshadows everything else in the email. Can you detect a hit of self-referential irony here? As in: think before you print this email, because my signature is like 3 pages on its own. Oh could it be? Could it be that behind that facade of stupidity there is a clever little mind, peeking out at you and saying “See what I did there?” Yes I see my friend, and I find it hilarious! I find your satire quite amusing!

Anyways, I think I offended the guy when I acknowledged his subtle yet clever joke. He explained to me that he just wanted to remind people to conserve paper because of the trees, and not self referent… Whatever I said, which was stupid anyway. When, oh when will I learn not to assume people are intelligent.

You may think I exaggerate a little bit here. I do in a way. This whole blog is about exaggerating things to a certain extent. I do it for the comical effect, and sometimes for the proverbial “shits and giggles”. If you think about it the signature is not all that horrible on it’s own, right? I mean you can clearly see where the email starts and when it ends and you don’t have to scroll down and read the whole thing each time. Unless of course you have been CC’d on a long top-posted email conversation between Mr. John Smith and Ms. I Also Like Long Signatures and the topmost email says simply “Luke, can you please take care of this matter?”

Sure thing pal. As soon as I figure out what the matter is, because apparently it is hidden somewhere inside this sea of stars, octothropes, images and colors. And I’m the lucky guy who has to scroll through 20+ pages of one line email replies followed by 5 pages of signatures. Wheee!

Python, Telnet and GUI-fying Legacy Apps

November 12th, 2008 11:31 AM by Luke Maciak

Today I want to talk about telnet. Yes, telnet is stupid and you should use ssh. Sometimes you can’t though. For example if there is some old legacy app that is sitting on some remote server that is not even yours and the only way to interact with it is via telnet session. We have one of these things at work - it is a little app running on a mail server that allows people to set up an auto-reply message when they go on vacation.

In theory this is something that every user should be able to do themselves. The instructions are simple enough. Go to Start, Run, paste this telnet command into the box, hit enter, follow prompts on the screen. The interface is easy to use, if a little clunky. I never had any issues with it. And yet, no one ever wants to deal with. That black window with the dreaded blinking cursor is incredibly scary it seems. Most people call the help desk and request a message to be set up for them instead. This is not the end of the world, but it’s backwards. This system does not have a main administration panel where we could set these things up from above. So when someone calls in with a request, the helpdesk must actually telnet to the system and use their username and password.

So I started thinking if we could dumb-down this process enough to make it accessible to our average luser. The idea was to have a GUI layer shielding the user from the scary telnet stuff. I hacked up a tiny little prototype app in Python and it looked a bit like this:

auto_reply.JPG

It is very simplistic - kinda ugly actually. It’s Python using the Tkinter widgets for GUI-fication. It is less than 30 lines of code once again demonstrating that Python can be very terse and concise language despite it’s strict whitespace regime - even when coding GUI apps. Observe:

from Tkinter import *
class AutoReply:
   def __init__(self):
      self.root = Tk()
      self.root.title("DG Auto Reply Tool")
      self.root.resizable(0,0)
 
      self.text = ""
      self.email = StringVar()
      self.onoff = StringVar()
 
      self.reply = Text(self.root)
      self.reply.grid(row=0, column=0, columnspan=5)
 
      eml = Entry(self.root, textvariable=self.email)
      eml.grid(row=1, column=0)
 
      status = Label(self.root, textvariable=self.onoff)
      status.grid(row=1, column=3)
 
      button = Button(self.root, text="Update", command=self.update)
      button.grid(row=1, column=1)
 
      toggle = Button(self.root, text="Auto Reply:", command=self.toggle)
      toggle.grid(row=1, column=2)
 
      self.root.mainloop()
 
   def update(self):
      pass
 
   def toggle(self):
      pass
 
if __name__ == "__main__":
   app = AutoReply()

This is what Python is good at - creating usable software really fast. Next step was to figure out how this GUI layer would communicate with the telnet application. I started thinking about sockets and streams and all that fun stuff. That was my first instinct - just open a socket and dump messages to it and try to see if I can get anything back. I did something like this before, and it was a lot of tedious coding just to get the communication between the client and server. Of course I was using Java to do it, which means there was a lot of tedious coding there in general.

Python on the other hand ships with a built in telnet library (aptly named telnetlib) and all you really need to do to connect to a server and start sending messages is this:

I didn’t want to do all of that.

import telnetlib
 
HOST = "my.remote.host"
PORT = 1337
user = "my-username"
password = "my-password"
 
tn = telnetlib.Telnet(HOST, PORT)
 
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")

You just follow this pattern for all your other interactions with the server. You read_until and then you write and etc. I abstracted this into a tiny self contained class, and made my GUI initialize it in the constructor and then call it every time it needed to send or receive data. I kept it simple - each transaction was self contained, connecting to the server, logging in, interfacing with the app and then disconnecting. This way I didn’t have to worry about keeping the connection alive, timeouts, disconnects and could pretty much rely that the app running on the server will be in predictable state when I connect to it.

The rest was just a bit of creative screen scraping. The read_until method returns a string, which I could break into lines, and then parse each line to extract the information I needed. It was pretty easy to isolate the important data and discard everything else. I’m not going to post the code here because it is really customized to the particular application, and thus probably useless to most people.

The GUI works pretty well, but it is synchronous - it will block until the read/write transactions are accomplished which is probably not the worst thing that could happen. I’m pretty sure I could do it asynchronously but it would take more effort and make no huge impact on usability. The blocking as it is right now actually works like a feedback mechanism that shows the user when sending and receiving is taking place.

My app is actually more user friendly because it allows you to edit the message as a whole in a familiar editor window. The telnet app forces you to type the message line by line. The only way to change a line already in place is to delete it, append new line to the end of the message and then move it up one line at a time until it is in the right place. Oh, and pressing backspace inserts the lovely ^H instead of actually deleting the character. So the GUI is much friendlier and I deal with the craziness by simply nuking the message and then re-inserting it every time the user clicks on update.

I haven’t unleashed it on unsuspecting users yet - it’s still buggy and unfinished. I’m just throwing it out here to show how easy it is to hack things like that together with just a little bit of Python. The complete app is tiny (only slightly over 100 lines of code - including white space). The only problem is that most of my users are not running Python. This of course could be solved by using py2exe but then I’m basically converting 3KB of python into 30 MB of crap. Not a perfect solution there. I could either deploy python, ship the app as a huge native package, or rewrite it in C#. What would you do?