Thursday, January 21, 2010

Doctest in Python

As part of my mission to learn a new thing each day I've ended up learning about the doctest python module today. It let's you add intepreter commands and responses as docstrings for each function and let's you run them, giving you feedback if anything is amiss. Here's an example:
def fib(x):
    >>> fib(0)
    >>> fib(1)
    >>> fib(2)
    >>> fib(3)
    >>> fib(4)
    if x == 0:
        return 0
    elif x == 1:
        return 1
        return fib(x-1) + fib(x-2)

if __name__ == '__main__':
    import doctest
Would return:
File "", line 11, in __main__.fib
Failed example:
1 items had failures:
1 of   5 in __main__.fib
***Test Failed*** 1 failures.
It's worth noting that python doesn't handle tail recursion very well, so we wouldn't like to try running fib() on very large numbers, but it's ok for this example

Sunday, January 10, 2010

Twitter Added to My GUI

I've now added twitter functionality to my blogger gui using the python-twitter api. One of the things I plan on doing this year is learning one thing a day and posting what I learned on twitter, not sure how long I can keep it up but we'll see. You can see how I get on here My Twitter Page

Monday, January 4, 2010

Websites and Tools

I started playing around with a new website yesterday, trying to learn css, javascript in preparation for my first facebook app.
Whilst doing this I realised that making websites seemed very repetitive, and the resulting pages don't seem very neat.
What I wanted was to get through to adding content as soon as possible, but most content management systems I looked at seemed much bigger and more complicated than I needed.
So I started writing some tools to make the whole thing a lot easier. This lead me to wondering If I could make posting on my blog easier, since my malaysian connection is slow, and I don't always have a connection when I want to write posts.
So I downloaded Google's Data Protocol which would let me build an app for uploading posts.

And here it is!

My first post using my blogger posting tool. Not bad eh? Notice how it also lets me format stuff offline:

def foo():
message = 'I can even write code'

At some point I hope to get around to publishing the tools I'm working on