Tag Archives: Programming

Django-resolvetime

Django-resolvetime is a Django filter to convert a python datetime object into a format that specifies the time difference between the time of the datetime and now. I developed this for a personal project of mine and decided to opensource since I could not find a filter available to get the job done.

The code is hosted at http://code.google.com/p/django-resolvetime/. Installation and usage of the filter is straight forward. Instructions are given in the README file.

Advertisements

Debugging in Python

Python has a simple yet powerful builtin module for debugging called pdb. Using this module you can debug your python code easily even without any IDE.

1. First step is to import the pdb module

2. Next step is to mark the entry point where the debugger would be called in. We use the set_trace() method for that.
pdb.set_trace()

3. When the program is run the execution would stop at the set_trace() method and would wait for debugging commands.

4. To run the next statment enter ‘n’ or ‘next’

5. To print a variable enter ‘pp variable_name’

6. To run until exit enter ‘c’ or ‘continue’

7. To display the current location enter ‘l’ or ‘list’
This would display an appropiate part of the source code with a pointer to the current statement.

8. To step into a method enter ‘s’ or ‘step’ when debugger is met with a method

9. To insert a break point enter ‘b filename:linenumber’

10. You can also dynamically assign values into variables.
Let’s assume there is a variable called num initialized to 10. You want to see what would happen when that variable is initialized to 20. You just do this. (pdb) num = 20 and then enter ‘n’ to execute next statement or enter ‘c’ to execute program until the end.

An example would look like this

import pdb

def method():
i = 10
name = ‘kasun’
last_letter = name[-1]

last_num = ord(last_letter)

print ‘last_num is’, last_num
if __name__ == ‘__main__’:
pdb.set_trace()
method()

All new Adobe AIR – Cool technology.

I have been playing with the newly released version 1.0 of Adobe AIR lately. To say the least it is really a cool technology. It could be used to build rich Internet applications that can be deployed to the desktop and run across different operating systems. To be more clear it is an environment which allows developers to build desktop applications that utilizes the client – server architecture.

One thing thats is a relief is AIR doesn’t have a new language(Another language to learn and i would have said goodbye to AIR). Rather it allows developers to use existing languages or technologies to build AIR applications. There are three options you could use to build AIR applications.

  • 1) HTML/AJAX
  • 2) Adobe Flex (another cool technology by Adobe)
  • 3) Adobe Flash cs3

Here are some sample applications in the official Adobe site

And here are some rapidshare links to some video tutorials to get you started in AIR.

http://rapidshare.com/files/97286863/LC.Ad0be.A1r.part1.rar

http://rapidshare.com/files/97291522/LC.Ad0be.A1r.part2.rar

http://rapidshare.com/files/97294946/LC.Ad0be.A1r.part3.rar