Programming


  • Monday, April 20, 2009 - 11:17

    For my Embedded Systems class I'm working on a project where we are doing some webcam capture and video processing/effects work. To make life simple we are using OpenCV, which rocks. Our language of quote-in-quote choice is C# and to work with OpenCV we are using EmguCV wrapper/binding/what-have-you. So, while working on code that has to capture a video frame, process the frame to do face detection and a video effect, then draw a frame to display to the user I decided to throw everything into its own frame.

  • Monday, April 6, 2009 - 13:16

  • Sunday, February 15, 2009 - 15:18

    The more I work with python the cooler it becomes, especially the more I let my mind think of way out there things to do with the tools python provides. In my work I frequently find my self writing code in this order:

  • Friday, February 13, 2009 - 15:22

    So one of the coolest things I just found out about python is that it will let you chain comparisons, so 1 < a < 10 works. Even 1 < a < 10 < b < 25, and so on, you can even get really crazy and try a < 5 > b, wich is a funky way of saying a < 5 and b < 5, pretty cool huh!

  • Monday, February 9, 2009 - 18:25

    So today I used my first function closure in Python. I had always wondered why/how someone would use them, but today after reading an article earlier this morning I ran across a place to use them while coding this evening. Here we go:

  • Thursday, January 29, 2009 - 23:38

    Every so often I try to write some code in MatLab instead of my beloved Python, it generally turns into a marathon even of trying to get MatLab to do what I know how to make Python do in a couple of lines. One thing that I am missing right now is Python's sort and the ability to pass it in a key function that will be used in sorting an array.

  • Thursday, December 11, 2008 - 10:37

    So I've run across the issu of tabs vs spaces again and have decided to put in my two cents. A nice overview of the topics is given here, but I disagree with is final conclusion. The topic actually consists of three points:

  • Monday, November 24, 2008 - 11:40

    Python has a really cool feature called decorators. Which allow you to wrap functions around other functions in a clean way. The classic example would be the @trace decorator which would let us do this:

    @trace
    def sayHello(name):
       print 'Hello %s!' % name
    

    If we define the trace decorator like this:

  • Thursday, November 6, 2008 - 16:57

    Okay, so things everyone should know about dictionaries, they are in the python manual but I still didn't know them until today. First off creating a dictionary in the code (ie hardcoded)

    d = dict(one=2, two=3)

    This is a simpler way of doing things, and it sure beats having to rember all your quotes when doing:

    d = {'one': 2, 'two': 3}

    Granted the second way looks cooler! But we have to make compromises. Another cool thing, is taking a list of keys and list of values and turning them into a dictionary:

  • Wednesday, October 8, 2008 - 23:31

    So I wanted to swap to objects, and I prefer to write short clean code, especially to carry out simple processes. The idea was that I have two objects, in this case treeA and treeB and I wanted treeA to be the deeper of the two trees. Now the long way would look something like this:

    if treeA.depth < treeB.depth:
        tree = treeA
        treeA = treeB
        treeB = tree

    Which is a little ugly, 4 lines to reorder something, so there neat trick is that if you want to swap two objects a and b simply use:

    a,b = b,a

    So the above code becomes: