Utah Python Users Group - 11/11/10

I've been messing around with Python for the past 6 months and I'm loving it. Today I went to my second UtahPython users group meeting and had a lot of fun and learned a ton of stuff.

Chronological order of things I learned:
  • Supy bot - an IRC bot written in Python. 
  • supybot-doxygen - A plugin for supy bot that can provide api documentation for any software that uses doxygen.
    • This could be really useful at work if I can setup an internal IRC server for the developers to hang out. 
  • Objectify is a module in python for parsing XML files. 
  • doctest - a python module for TDD that is super simple. I'm really excited about this. Thanks to Matt for showing me how to use this.
Matt suggested that we do some pair programming during the meetup.
Here's the task: Write a simple python program that can take page numbers as user input and convert it to a list of numbers. 
User Input: 0, 1, 5, 7-10
Output: 0,1,5,7,8,9,10
Here is the code I wrote with the doc test based unit test in the doc-string:
###### PrintParser.py #######
    
    #!/usr/bin/env python

    def convert(inp):
        """
        * Get the input from user.
        * Parse the input to extract numbers
        ** Split by comma
        *** Each item in the list will then be split by '-'
        **** Populate the number between a-b using range(a,b)

        >>> convert("")
        []
        >>> convert("1")
        [1]
        >>> convert("1,2")
        [1, 2]
        >>> convert("1,2-5")
        [1, 2, 3, 4, 5]
        >>> convert("1-3,2-5,8,10,15-20")
        [1, 2, 3, 2, 3, 4, 5, 8, 10, 15, 16, 17, 18, 19, 20]
        """
        if not inp:
            return []
        pages = []
        comma_separated = []
        comma_separated = inp.split(",")
        for item in comma_separated:
            if "-" in item:
                a = item.split("-")
                pages.extend(range(int(a[0]),int(a[1])+1))
            else:
                pages.append(int(item))

        return pages

    if __name__ == '__main__' :
        import doctest
        doctest.testmod()

Hapkido First Impressions

I went to my first Hapkido class today. I have a very good (and respected) friend from work, who is already taking that class and he recommended it.

I had high hopes for that class, maybe a little too high. It was a little bit underwhelming due to my overtly hyped expectations. It is definitely more exerting (physically) than Aikido. It combines the kicks from Taekwondo with the joint locks in Aikido. So I'm excited to keep learning the art. But the part that bothers me about Hapkido is you attack to destroy, unlike Aikido where you take care of your opponent even when you are pinning them down and making them submit. 

But one great thing about the class is the instructor seems really good. He is very friendly and knowledgeable. If you are in Lehi/American Fork area you should check out the class. xsifactory.com/martial-arts-classes/

Mmmmm.... Rice

After three days of not having any rice, I finally made some today. Is it just me or does every one well up a little bit when they are about to taste rice?

So if I like rice so much, why don't I make some every day, you ask. Well, I'm a lazy bum who doesn't enjoy cooking as much as eating. There, I said it!

Vita Brevis [Ars Longa]

InnerVoice: That is latin for "Life is Short, Art is Long". 

Me: Yeah, I know, I'm a little behind on my personal projects.
InnerVoice: Try waaaaay behind. There are at least ten tabs open at home and five tabs open at work 
Me: I'll get to it. They are not going anywhere.
InnerVoice: BTW, those unread emails with some tutorial links isn't gonna master itself, you know.
Me: Hmmm..... 
InnerVoice: Are you even listening to me?
Me: Barely. I'm still thinking about my first Hapkido class tomorrow. 
InnerVoice: Well, there goes the Wednesday nights.
Me: BTW, I agreed to present a brief tutorial on Git at the SLLUG meeting next Wednesday (Nov 17). 
InnerVoice: What? Are you crazy?
Me: Well how else am I going to make a good first impression?
InnerVoice: You do realize, you've never been to one of those meetings, right?
Me: Yeah, but they seem like nice people. I'm sure I'll be fine. 
InnerVoice: *Shakes Head* Hopeless, utterly hopeless.
Me: *Grinning with glee*

It's awesome when life gets busy.

Bad day all around

I went to a Beans and Brews in American Fork to get some work done. It was a total disaster:

  • I decided to try dirty Chai (Chai w/ espresso ) which tasted terrible.
  • I got no work done, thanks to the noisy coffee grinder and their horrible excuse for a music.
  • My netbook was having too many problems and I gave up trying to get any work done on it. Time to buy a decent laptop.

On my way back from this defeated attempt to work at a coffee shop, I was stopped by a cop for speeding.

  • I got my first speeding ticket in Utah County. 
  • I realized that I'm about as useful as a concrete parachute when I'm stopped by a police officer. I really need to work on my communication skills. 

Got back home and checked my email to find out, I've ruined my chances of going to an Aikido seminar. 

  • My less than tactful communication with my Aikido teacher barred both Yoshi and I from attending an Aikido Seminar in December.
  • I might have angered him and created more political discomfort.

I don't think I can salvage this day.

I'll just go back to my corner and produce some more code that the world doesn't need.

Cows and Bulls Game

A typical Saturday evening conversation between me and my inner voice. 

Setting: Salt Lake Roasting Co., after an intense Aikido training. 

Me: I'm bored. 
Inner Voice: Go take a nap.
Me: Meh! I think I'm gonna do some Python coding. 
Inner Voice: What are you going to code? 
Me: Remember the Cows and Bulls word game that I used to play when I was little.
Inner Voice: What? That sounds kinda lame. Work on something productive.
Me: Screw you, Inner Voice!!
Inner Voice: I don't like you very much. 
Me: Oh yeah, well the feeling is mutual. 

So I fired up Vim and coded up the Cows and Bulls game :)

It is text-based right now and still in its primitive stage. I'll probably add more features when I get into a fight with my Inner Voice again. 

Happy for a friend

My buddy just told me that his wife is 11 weeks pregnant.

An exchange we had over the phone: 

Anand: If we have a boy, we'll start receiving applications from potential brides. Would you guys be interested in pre-applying? 
Me: Well if we have a girl, I'm sure she can kidnap your boy without any trouble, saving us the trouble of application fees. 

I'm freakin' excited for Anand and Abirami. 

Brain Spill

Brain spill is a dumping ground for my incoherent thoughts and incomplete ideas. It'll be training ground to practice my writing skills.