Archive for the ‘python’ Category

osgeo.codepad.org

Saturday, October 24th, 2009

Online compilers are another generation of collaborative debugging tools delivered to Open Source communities. The overall idea is great. Actually, I can not imagine online discussions on IRC channel without being able to paste code snippets or compilation logs.

The codepad.org provides feature called private and project pastes. Some time ago I proposed private general purpose paste service dedicated to OSGeo communities. it is hosted at osgeo.pastebin.com and people has found it useful, as I can see. Today, I registered osgeo.codepad.org – a programmers-oriented paste service. Perhaps, people will find it useful too..

Users of the World’s second best programming editor, Vim (first place taken by Emacs), can install codepad.vim plug-in and send Vim buffers as pastes directly to the codepad.org service. Kudos to Nicolas Weber for the plug-in!

I’ve taken the liberty and modified the plug-in to use the private service at osgeo.codepad.org – here is custom codepad.vim plug-in.

Online Compilers

Saturday, September 26th, 2009

Sometimes I need to compile and run a tiny snippet of C++ code. For example, I want to proof some concept or I want to give code example while chatting with friends. Sometimes I don’t have access to good compiler. If I’m logged to irc.freenode.net, it’s not a problem – geordi is there. I’ve just found a Web-based alternative – codepad.org. It is a pastebin service that can compile, validate and execute your code.

Hello World!

Snakes in Oracle

Wednesday, May 6th, 2009

Latest Oracle’s Dev2DBA newsletter issued in May 2009 brings a nice collection of articles revealing some tips for getting the most out of Python and Oracle.

Most of the articles are accessible through Python tagged bookmarks of Oracle Technology Network.

Looks like must read resource for all Pythonistas living in the Oracle.

Turing award goes to Barbara Liskov

Friday, March 13th, 2009

Learning principles of Object-Oriented Programming, one of the first and very important thing to understand is a definition of subtype. It’s usually not a big problem to explain it correctly and there are a few descriptions dangling around.

Of course, I have my favourite definition of the relation between supertype and subtype. It is called Liskov Substitution Principle. The LSP reveals existing subtleties that may make understanding of the term of subtype not easy. There is a well-known example presenting potential problems: a squere is a rectangle or may be it is not? Robert Martin has written more about in C++ Report long time ago (PDF). For a C++ programmer, like myself – who cares about design by contract (DbC) – the Liskov Substitution Principle is helpful to understand role of pre-/post-conditions in inheritance.

The Liskov Substitution Principle was formulated by Professor Barbara Liskov (MIT). Two days ago, BBC announced as follows:

The 2009 A. M. Turing Award has gone to Barbara Liskov for her contributions to programming.

(Barbara Liskov wins Turing award, BBC)

Congratulations!

Lambda, I love you!

Thursday, March 12th, 2009

I’m writing a small driver for readint WKT Raster data from RASTER column in PostGIS-enabled database and I want to report name of database I’m connected with. My reader eats connection string, and here I’ve fallen in love with Python lambda.

Given connstr stores connection string to PostgreSQL database in format well-known from libpq, single-line anonymous function can do the whole job:

filter(lambda db: db[:6] == 'dbname', connstr.split())[0].split('=')[1]

Complete example:

$ python
Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
>>> connstr = "dbname='rtest' host='localhost' user='mloskot'"
>>> filter(lambda db: db[:6] == 'dbname', connstr.split())[0].split('=')[1]
"'rtest'"
>>> connstr = "password='xxx' port=5432 dbname='rtest' host='localhost' user='mloskot'"
>>> filter(lambda db: db[:6] == 'dbname', connstr.split())[0].split('=')[1]
"'rtest'"
>>>

Have fun!

Run GDAL builders in a batch

Friday, September 14th, 2007

In my daily work, I have to run GDAL builders very often and simultaneously. Each time I need to request new builds, I have to make 20-30 clicks. So, when it’s third or fifth round of building, every click hurts :) and here comes the genius of Python language.

I wrote a simple utility script – gdalbb.py – that simplifies running one:

gdalbb.py -b telascience-quick

or whole family of builders from the GDAL Buildbot instance:

gdalbb.py -f

in one shot. It can also list all builders available from the Buildbot instance:

mloskot@dog:~ gdalbb.py -l
Connecting to GDAL Buildbot instance: http://buildbot.osgeo.org:8500/
List of available builders :
1. telascience-quick
2. telascience-full
3. epimetheus-full
4. szekerest-vc80-full
5. szekerest-vc71-full
6. szekerest-vc80x64-full

It’s very easy to customize the gdalbb.py script to use it with other Buildbot instances available for OSGeo projects. Just edit three values in the configuration block of the script:

### BEGIN CONFIGURATION BLOCK ###
BBURL = 'http://buildbot.osgeo.org:8500/'
BBUSER = 'mloskot'
BBNOTE = 'Routine build'
#### END CONFIGURATION BLOCK ####

That’s it!

Perhaps, as a next step, it would be a good idea to make this script usable as an IRC bot.

FDO goes for Python

Wednesday, March 14th, 2007

A few hours ago, guys from the core development team of Feature Data Objects submitted new cool stuff to the FDO repository – Python scripting support for FDO API.

The Python bindings are generated with SWIG. As Greg Boone reported on the fdo-internals, currently Python bindings can be generated and used on Windows only. Linux support will be available soon. Also, it has been only tested with Python .2.4 so far and 2.5 line is not supported yet.

The Python scripting support for the Feature Data Objects is still under development but I’m sure it’s a great news for the large community of Python users in geospatial field. This is a next step to attract potential FDO users.

There is more about pyFDO subject on Jason Birch’s blog: pyFDO is in the House – Yeah Baby!