How to kill momentum instantly

Posted by Nick on February 16th, 2009 filed in Google, Programming, Python, django
Comment now »

  1. Get the itch to finish a stale project
  2. Carve out some time to work on stale project
  3. Upgrade your software stack to make sure you are current*
  4. Spend hours figuring out something simple isn’t working
  5. Curse, debug, repeat
  6. Curse more when you realize that step 3 was where the train went off the rails

Yes, I made the mistake to upgrading the Google App Engine Launcher only to discover that for some reason it doesn’t play nice with the Django Helper project (or apparently the latest version of Django).

*sigh*

I know, I can go and continue development without those tools, but I was really looking forward to playing with the AppEngine (using a Django project).

Some days you are the pigeon, some days you are the statue.


Unicode: Feel the burn

Posted by Nick on January 18th, 2009 filed in Python, Software Development, django
Comment now »

There’s nothing worse than having a program that has been running great for X amount of time suddenly start crashing. Especially when you discover that its choking on unicode characters you didn’t expect.

With web addresses (or URLs if you prefer) starting to have unicode values in them, this is a problem that will probably be more common. I noticed this problem when trying to get to web pages that had special characters in them (for example, URLs that feature characters with accent symbols such as in the Spanish language) would cause urllib2.open() to fail. Several website suggested url encoding these special characters, but I didn’t have much luck with it.

Also today I was using Django’s model layer to store some data (web pages) into a database so I could try some things out. Even though Django is unicode friendly, if there’s the slightest problem in mapping text it will pull out the dreaded UnicodeDecodeError at some point.

To get around this I wound up just using unicode(text, errors=’ignore’) to make sure that the text that was being passed in was indeed unicode, and to ignore any errors that cropped up. Not ideal, the better solution would be to map correctly, but better than being stuck with data you can’t load/process.


Pickle Danger!

Posted by Nick on January 11th, 2009 filed in Python, Software Development
Comment now »

I’ve been poking around with a little python based web crawler/robot/scrapper that I’ve written. Its a pretty simple script and over time I’ve added little bits and pieces to it in order to try improve, etc. etc. etc.

One thing I added was an ability to track the URL’s I’ve already visited. Trying to be a polite, I decided that this was a good thing to keep from hammering the same web sites over and over needlessly. Basically, I put the address into a dict, and then after a successful visit to the address I set the value of the address to 1. (This way I could collect addresses, but no visit them right away, but always make sure I got back around to visiting them. Or if I needed to visit them multiple times I could keep track of how many times I’d been there.)

Python provides a really simple way of serializing data by using the pickle module. Just open a file, then call the dump() method with the file and the data as parameters, and boom, all done! Going in reverse and reading serialized data is just as simple.

Except…..

What happens if there’s an exception thrown in your code? (Bad URL, unicode that you’re not prepared to handle, network down, etc.) And what happens if this happens to occur while it is trying to dump the data your interested in? Well friends, I can tell you: It ain’t pretty.

Because I had already called file() on the data file, the old data was gone. *poof*. Since the new data was being written out when the new the problem occurred, the new data file was corrupted.

There are several lessons that can be learned from this:

  1. If you are going to re-use a program/script more than once, go ahead and build it right.
  2. If you are going to write out data make sure it is either
    a) Backed up first (i.e. write to a different file first, then after the file is closed successfully, overwrite the old one)
    b) Written to something like a database which is designed to not get corrupted at the drop of a hat

And as a bonus tip: You should always back up code (and data) that you generate. As I said, this was a quick-and-dirty program at first, but it had obviously grown in it scope and importance. My new metric for “needing to back this up” is if I have checked the code into a repository: If you are willing to check in the code, you need to save the data (config, output data, etc.) as well.

Fortunately I didn’t loose that much or anything that was earth shattering. But all it takes is one time…


Tab vs. Space, part XIV

Posted by Nick on July 20th, 2008 filed in Apple, OS X, Programming, Python
1 Comment »

So, lets say you are working in XCode 3, and you are trying to build a PyObjC app but for some reason the python code you wrote isn’t getting called.

If you are seeing weird errors in the console when you run the application (specifically “Could not connect the action <your_action> to target of class <your_AppDelgate_class>”), here’s what it probably is: In the AppDelegate python file that XCode creates it uses spaces to do the indentation of the methods.

I hail from a land where tabs are used for such tasks, and the use of spaces is look down upon in much the same way that pick ones nose in public is.

At any rate, what’s happening is when the code is compiled/run the python interpreter is not recognizing the new methods that I put in (using tabs to indent) and instead of giving me a warning about inconsistent indention, it fails somewhat silently in that it groans it can’t hook the action up to the class and that’s it. It wasn’t until I turned on the invisible characters that this occurred to me that it might be the root cause of my problems.

Once setting all of the indentions to be the same, I chose tabs, everything worked like a champ.

By the way, if you are looking for some tutorials for PyObjC in XCode 3 (there are a ton of XCode 2 tutorials out there, but things have changed ever so slightly in 3), be sure to check out these links:


XCode 3’s SCM makes me sad.

Posted by Nick on July 7th, 2008 filed in Apple, OS X, Programming
Comment now »

I just finished trying to use XCode 3’s built in support for Subversion. It did not end well.

For starters I created a new XCode project, ran it to make sure it could build, and then decided to check it in to svn so that I would have a “clean” starting point in case I ran into problems. This is how I normally work in other IDE’s, and I’ve never had a problem. Until today.

After setting up the repository in XCode I couldn’t find how to set the project so that XCode would “know” it was under version control (or SCM as XCode refers to it). If you look at the project’s properties, there is a drop down list the lists the available repositories (or it offers to let you set up a new one, which is a nice shortcut). However, the repository I just added is grayed out. After a half hour of trying various “obvious” things I gave up and googled around.

It turns out that XCode can’t create and then check in. The project has to be put into the repository, then checked out before XCode will recognize that it is under source control. Very unusual, but what ever, I decided to play along.  I used XCode’s svn browser (which isn’t half bad) to upload the code, then deleted the project and checked it out.

And right about then is when it became obvious that I was traveling the wrong way on a one way street. Here’s an executive summary of what I found so very, very, very wrong with XCode’s SCM integration:

  1. I had to create the project, check it in, then check it out for XCode to realize that it was under version control.
  2. Although XCode has an svn repository browser that allows me check in and out the code, it doesn’t seem to know anything about XCode projects as it checked in the build directory without asking. For me (and a lot of developers I know) the last thing I want in version control are files that are going to change constantly (i.e. object files). Checking in a finished version, fine. Checking in a ba-jillion intermediate files: fail.
  3. After checking out the project, XCode began complaining about there not being a lock on a file in the build directory. The error message actually said “This might be a bug, please report it.” Sorry Apple, I’m a nice guy, but I’ve got limits. This seems like something that shouldn’t happen on a fresh project (i.e. all boilerplate code, I haven’t done a thing to the project yet).
  4. Deciding that I might be slightly smarter than the computer, I decided to delete the build directory in the repository. I tried to refresh the project to let it know there was a change it might need to be aware of. Instead I was made aware of the fact that there doesn’t seem to be one central view of what’s changed for the project. The near-useless SCM menu item in the project reported that one file had change, and I could not seem to get it to even look at the project as a whole. Maybe I’m spoiled by the way Eclipse handles this situation (which provides a bunch of clues in different areas, but all of which lead to a pretty straightforward GUI for dealing with changes). Even TextMate handles this decently (just not as good looking as Eclipse).

By this time I just gave up. I removed the repository connection from the project settings, and decided to just go Command-line for doing my updates/commits. Life’s too short to be chasing my tail on stuff like this.


A good cup of Tea (and coffee)

Posted by Nick on March 25th, 2008 filed in Fun, Programming, Thinking
Comment now »

I haven’t written much lately because I’ve decided to having two ears and one mouth probably means I should spend more time listening rather than talking.

It is an interesting exercise, trying to tune the world in while not adding to the noise. For programming I think this is an essential skill, it is how one learns new things. Lately I have found that having a good cup of hot tea and sitting back to take in things (bugs, new ideas, etc.) really helps me to move forward.

I’ve been hanging out at my favorite independent coffee house Tazza doing some programming work and thinking, and I have to say its a really cool place to hang out. I love the hot tea there, and from what everyone has told me the coffee is really good. The staff (hi everybody!) is very friendly and love to chat. That along with the cakes and cookies combined with the great (and free!) WiFi makes this little coffee bar the ultimate place for me to get away from the grind of the office.

I always wondered why some developers hang out in coffee shops, and now I think I know why: its a good place to be in order to keep your perspective. I might be the only programmer in there, so hearing other people talk about other things helps me to keep things in the right light.

So if you are in Atlanta (especially the Buckhead/Midtown/Georgia Tech area) you owe it to yourself to drop in to Tazza and enjoy a good cup. (The address is 1700 Northside Drive, Atlanta GA 30318 or just use this link)


Never were truer words spoken (or typed)

Posted by Nick on December 31st, 2007 filed in Fun, Games, Programming
Comment now »

The other day I came across this really cool posting talking about school projects for computer science students.
Basically it talks about the different “levels” of effort required to make a certain type of video game for a CS class. Having just finished a CS class that involved a group project (but not a game) I was intrigued by the author’s take on the topic. (I usually try to dissuade people from doing games as a CS project, they just eat up too much time usually unless everyone in the group is on the same page.)

Overall I found myself agreeing with the various comments and evaluations of each game type (pacman, tetris, etc.). But when I got to the end of the “Advanced” topics section, I laughed out loud:

RPG – if you hate your life (and some apparently do), this obviously final year attempt at video game programming glory is likely to end badly.

That pretty much sums up my experience so far with my attempts to make a “simple” RPG. There’s a lot going on in a typical RPG, and it takes a lot of effort and attention to detail to pull it off and make it look good and play well. And even then, if you manage to get the mechanics of the game engine working semi-decently, then you have a tall order to fill by creating the contents (scripts, maps, graphics). Needless to say it can quickly become a huge time sink. Which isn’t to say it isn’t fun, because it is. But when you get overwhelmed on a project like this where you are working for yourself (i.e. not getting paid to work on it) it becomes very difficult to get your motivation back.

Personally, I’m hoping to get my motivation back to work on my little project some more. I think what I’ll probably wind up doing is working on it in-between other projects.


Why I like the SICP book

Posted by Nick on November 1st, 2007 filed in Lisp, Math
Comment now »

The Structure and Interpretation of Computer Programs is turning out to be a rather awesome read. What makes it so cool for me is that I’m taking a class in Numerical Analysis, and in sections 1.2 and 1.3 the examples read like something right out of the class. The really odd thing for me is that this “double teaming” of my brain is paying off in that I’m learning the Lispy things, and at the same time I’m learning the Numerical things. Each one builds on the other, reenforcing the lessons learned. Very recursive, just like Lisp.

One of the things I have learned just today is that loops are actually allowed in Lisp. All of the recursive thinking I’ve been doing lately has made me think that there’s always a way too write a loop in a recursive manner. But, I was looking at Neville’s Method the other day and it struck me that with it’s nested loops, that could be quite a challenge to write it in a recursive manner. While trying to find an example of nested loop in Lisp, I found all kinds of cool links I thought I would share:

Go check them out, they are great resources!


Learning Lisp

Posted by Nick on September 24th, 2007 filed in Lisp, Programming, Thinking
Comment now »

One of those “personal/professional” development things that you should do every so often is try to learn something new in your field. For me, I’ve decided I will learn more about Lisp, and programs in general.

To that end I’ve been working my way through the book The Structure and Interpretation of Computer Programs which is a dense volume that is chock full of good knowledge about how computer programs work from a critical and analytical point of view. The language the book uses is Scheme which is a variant of Lisp.

Having worked with XEmacs and its version of lisp (called appropriately elisp), I thought I would be able to pick up Scheme pretty quickly. This is pretty much true, since the two languages have the same general syntax/form. One thing I don’t have those is a Scheme interpreter! I did install SBCL and CLISP a while ago, so I figured that I would just use that.

Well, it turns out that Scheme is also slightly different than Common Lisp. :) But thanks to Peter Seibel and his excellent book “Practical Common Lisp”, I was able to translate the first few programs in the SICP so that they would run in my CLISP-Slime environment.

So if you find yourself in this situation, be sure to check out the best Common Lisp tutorial on the net. Its free and it is very well written, so I highly recommend it. I remember playing around with it a while ago, and being impressed with it back then. The good news is it is still as good now as it was then.


CSS + Javascript + web = fun Easter eggs!

Posted by Nick on September 22nd, 2007 filed in Entertainment, Fun, Games, Programming, Web
Comment now »

It occurred to me the yesterday, with more and more people seeing the power of Javascript and CSS, more websites are getting slick. Ok, that’s a pretty obvious statement, but here’s something that’s not obvious: This presents a great opportunity for easter eggs!

Easter Eggs are little hidden things in side of a bigger program. Some times it just the developer’s names, other times it can be something totally unexpected like a flight simulator hidden in a spreadsheet program. With the power of Javascript and nice tutorials like this one, there’s a lot of opportunity to have some real fun!

Just think, with all of the computing power a modern browser affords us developers, it should be very easy to recreate tons of games from the Atari 2600, early Nintendo systems. The imagination can very easily run wild….