Code Jamming: Backronyms

jamExcuse me if I reference my first post ever on this blog but it’s right: I am very bad at following through with projects. I am, however, very good at following through with commitments and promises I have made.

Luckily I have friends with good ideas, and one of them came up with this one: every few weeks hold a “code jam” that gets all of us both excited and motivated about projects we could do. If we make it a commitment to each other to work on the projects and just feed ideas off one another, it will mean projects are more likely to get started and to get completed.

We decided to start with something easy. The organizer of the group, Kevin, recently posted about the problem of generating backronyms. There is an internet site out there does this, but it doesn’t do a very good job.

Well, let’s back up: what are backronyms? Sometimes you have a clever acronym you want to create for a project but you don’t know what the letters should stand for. So you invent the words that the letters stand for out of whole cloth! This is a backronym. This is used all the time in government: an example would be the USAPATRIOT act.

Well, the group has met three times and we have come up with three different algorithms for how to do this. I’m the first one to get my algorithm ready to run so it’s up now! On the internet! You can find it at pheared labs. It’s written in Python using django.

At first, it was only able to make sensible things out of 3 letter acronyms (try your initials). I’ve recently improved the algorithm so that it does fairly well with up to 5 letters and I hope to make it better. I also hope my friends will come up with their alternative algorithms so we can have more options.

If you live in or around Silver Spring and would be interesting in attending a Jam, let us know! Exciting!

Pycon 2009 Day 2

Day two of the Python Programming Language Convention!

I got up and headed out at 7:45 to attend the morning lightning talks (luckily I hadn’t been out all too late the night before). I didn’t know what to expect: lightning talks are 5 minute talks on whatever topics people had decided to speak about the day before. Many of them were funny or just plain fun, but one of them stood out for me in particular. It also foreshadowed the rest of the day: today was to be the day of useful tools.

Anyway, the lightning talk that really interested me was on a tool called SQLPython. It makes talking to Oracle databases (which I sometimes need to do for work) very easy by creating a shell for them that gives you interesting UNIX-style commands like ‘ls’, ‘cat’, and ‘grep.’ I will definitely be looking into this further.

After the lightning talks was the keynote by the inventor of Python and “Benevolent Dictator for Life”, GvR. Guido’s talk was a little underwhelming, but as always interesting. I think he may be burned out on giving keynotes after doing it every year for many many years in a row.

Anyway, then I attended two more talks about tools that seemed very useful. First was The State of Django. Django is the darling Web Framework in Python and, while I have never used it, this talk definitely made me want to. It didn’t hurt that the next talk, Pinax: a platform for rapidly developing Websites was about a tool that is built on Django and lets you build sites with all kinds of social networking widgets automatically available (thing like wikis, tagging, user management, user signup, photo sharing, etc). This definitely made me want to get my brother (the idea guy) to come up with some ideas for sites that I could try to implement for him.

Lunch was just as fancy as the day before: pasta with a tomato sauce, broccoli, and key lime cheesecake.

After lunch I only attended 3 talks (out of a possible five). The first was a panel on Object Relational Mappers, which help you to define and use a database without leaving your Python code. This was not as interesting as it could have been, but ORMs definitely seem like they might be useful tools.

Then it was time for another tool that might be fun: I attended Seven ways to use Python’s new turtle module. Turtle, if you don’t know, is a cool way to teach young people how to program by giving them a little turtle on the screen that they can control. They can move it around the screen and have it draw lines and do other things; this cute old high school teacher from Austria was demonstrating the turtle package he had written and gotten included in the Python Standard Library. The talk had a lot of cool examples and, though he ran out of time, definitely made me want to show turtle to some folks and get them to learn Python.

Finally, I attended Python 2.6 and 3.0 compatibility which was a little dry, but very important information to have.

After the conference events, some coworkers and I went down to the Logan Square area of Chicago and went to a restaurant called Lula Cafe. It was sleeting at the time, and very cold. The food was good and we had planned to go to another mexican restaurant in the area after, but the weather was just too harsh. We made our way back to the hotel and hung out in the bar next to a fireplace. We had the prime location for Earth Hour, when the hotel turned out all the lights for an hour, and I tried my first margarita. My coworker Dan is an excellent photographer and took some cool pictures; if I get access and permission I may post a few here.

I am very excited for tomorrow’s keynote, by the creators of Reddit. Let’s hope I can wake up on time!

PyCon 2009 Day 1

python-logoAh, the business trip. I’d love to say I know it well, but I don’t, because this is my first one! I am attending PyCon, the convention for U.S. users of the Python Programming Language. This year it’s in Chicago so in exchange for helping to do a little bit of recruiting and helping get the name of my company out there, I get to attend cool talks and network with other pythonistas from all over.

I attended six and a half talks today (out of eight possible) and all of them were very interesting and informative.

The firt was Python for CS1 Not Harmful to CS Majors (and good for everyone), which basically summarized the benefits of using Python when teaching the entry level Computer Science course in universities. Non-majors actually learn enough to put it to use, majors do just as well in CS2 (even if the course is C++ or Java) and it builds the Python community at the university among TAs and grad students. I liked this talk a lot even though it was pretty much only pertaining to academia and not all that useful to me in my work. Who knows, though, one day I may stop being able to do and start teaching.

Next was Python in the Enterprise – How to Get Permission. This was mainly a work decision because, while we already use Python at my company for “The Enterprise,” we sometimes have to deal with customers who are wary of it or cooperating organizations who are the same. The scope on this one was pretty narrow and pretty much could be summed up as “work within the system and tout Python’s benefits” but it was still good.

Apparently the speaker for the next talk missed his flight from Africa and so it was postponed. Hopefully I can catch Giving back and helping expand the Python community. A roadmap for South America and Africa on Sunday. Since this was the only talk I really wanted to go to during this time, I headed over to our booth for recruiting. It was just about set up, and a few other coworkers were hanging out. We started shooting our nerf rockets (with our job website on them) at the sparse crowd.

(The vegetarian) lunch was Caesar salad and lasagna with some sort of cream sauce. Also, Teramisu (it very much seems like they are trying to caffeinate the attendees heavily).

After lunch, I was conflicted about which talk to attend. I ended up attending Strategies For Testing Ajax Web Applications because it was helpful for my work, opting out of both a talk on capturing neutrinos in Antarctica (cool) and a panel discussion on the different Python interpreter implementations (cool and brainy). The panel discussion was extra long so I was able to catch the end of it.

The fifth talk I attended was called Python in a Sandbox by the implementers of PyPy (the Python interpreter written in Python). An interesting adjunct of their work is that they can abstract all the operating system calls that Python does out and replace them with whatever they like; for example, they can write an interface for reading and writing files that never actually writes to the machine, it only simulates the fact that there is a file system. This version of PyPy could eventually be run inside Web browsers safely, without giving Web sites dangerous access to your home computer.

After a short break, there were two talks left. I chose Introduction to Multiprocessing in python, about the new multiprocessing module (I know little about this, but it seems cool) and Easy AI with python which was very interesting and well-presented and led me to two modules I definitely want to experiment with – one on Bayesian filtering and one on simulating neural networks with a relational database. The code he showed for each of these things seemed incredibly simple (Python almost always does) but also very powerful. Maybe I can do that Bayesian work I was looking into for the Netflix prize.

After the talks, I hung out at our recruiting booth for a while and also checked out a few of the other booths. EVE Online was there, which was very cool, and they talked a little bit about their MMORPG. Then I got invited to a blues club by some coworkers; I turned them down (the main act didn’t even come on until 10:30 and I need my beauty rest.) Instead, I opted for the “board game social.” I learned two new games that I enjoyed immensely and want to buy, and met a few people. We went out to eat at a tiny Polish restaurant in Chicago proper. I had Pirogi.

And so ends the first day of the Conference. I am looking forward to keynotes tomorrow and Sunday by Guido van Rossum (inventor of Python) and the Reddit guys!

Have we turned everyone off? No? Let’s throw in some programming!

Since I figure my LCS posts don’t turn enough of my regular readers off (the ones who like to hear juicy stories from my now-boring personal life!) and since LCS is now off the air, I guess I’ll move onto some more esoteric and geeky fun.

My friend Mr. Wellons loves his number theory and programming puzzles! He recently offered up this fairly simple one:

What is a number that has the largest number of its permutations be possible dates without slashes?

For example, 01082008 is a date, but another permutation, 08102080 also is.

This was a pretty easy problem, here was my program to generate my solution:

#!/usr/bin/env python

import datetime

def is_date(num):
    padder = str(num).zfill( 8 )
    try:
        return datetime.date(int(padder[4:8]),
                             int(padder[0:2]),
                             int(padder[2:4]))
    except:
        return 0

def normalize(num):
    ls = list(str(num).zfill(8))
    ls.sort()
    return ''.join(ls)

best_date = (0,0)
all_dates = {}
for i in range(1010001,12319999):
    if is_date(i):
        j = normalize(i)
        all_dates[j] = all_dates.get(j,0)+1
        if all_dates[j] > best_date[0]:
            best_date = (all_dates[j],j)
            print best_date

Can anyone improve on that? And does anyone have any ideas as to why there is only one unique answer and it is what it is?