web developer & system programmer

coder . cl

ramblings and thoughts on programming...


integrating selenium and django

published: 12-12-2011 / updated: 12-12-2011
posted in: development, programming, python, tips
by Daniel Molina Wegener

As you know, using unit tests will only provide a testing over algorithms and low level interfaces. For a higher level approach, you have the automated testing suite that provides the Selenium, which provides you a test case API to be used in functional tests. If you want to automate functional tests under Django, you can use the selenium IDE to record your actions on the web site, and export them as test case instructions for the selenium API, which will run those tests as you in the web browser, or even other tools like Html Unit. This includes several browsers supported by the API, including a server that allows you to mount a test grid using various machines.

why to go with multi-paradigm?

published: 18-11-2011 / updated: 18-11-2011
posted in: development, programming, python, tips
by Daniel Molina Wegener

Hybrid languages are cool. Most powerful programming languages are those languages which can handle a multi-paradigm scope. You can reduce the amount of code considerably when you are using a multi-paradigm approach. Due to the imperative origin and procedural approach of object oriented languages, having only object oriented language approach is not enough to solve problems. For example as we reviewed the widely used MapReduce distributed computing model has its origin on the functional paradigm in two higher order functions called map and reduce — where the synonym of reduce is fold, applying a kind of Monoid where the data is lifted and transformed by the map function and then is processed and reduced by the fold or reduce function.

instant xml api using pyxser

published: 05-11-2011 / updated: 05-11-2011
posted in: development, programming, projects, python, pyxser, tips
by Daniel Molina Wegener

Probably you do not understand pyxser at all. It is a serializer and deserializer which converts Python objects into XML as plain text. Among JSON and other formats, XML can help in some tasks like transmitting object through the network, for example building API calls using remote queries. Here I will guide you on how to build an XML query API for your Django driven application in few minutes. You just need to understand how pyxser works and how to use the pyxser module. Remember that you can see the documentation once it is installed, even if you do not have Internet, just by running the pydoc daemon with pydoc -p 8080 and connecting to the port 8080 in your machine — you can choose another port if it is not working.

re: monoids in python

published: 12-10-2011 / updated: 15-06-2012
posted in: development, programming, python, tips
by Daniel Molina Wegener

On a recent post on his blog, Francisco Mota has described Monoids with both, the Mathematical background and the functional background. If you read careful the post, you will notice that he has created the Monoid class. He describes a Monoid as a set A with neutral element \varepsilon and an the operation ( \cdot ) : A \times A \mapsto A, where the triple \langle A, \varepsilon, \cdot \rangle denotes the Monoid. In terms of Category Theory, the set should be a category and the operation should be a morphism.

custom aggregates on django

published: 28-09-2011 / updated: 28-09-2011
posted in: development, programming, python, tips
by Daniel Molina Wegener

Python provides a query API through its ORM library. All models can define queries using the most common aggregates like Sum, Avg, Max, Min and Count. Since you cannot use SQL functions with Django aggregates, you must define your own aggregates to be used with functions. For example in one of my recent projects I’ve used some MySQL functions — and PostgreSQL functions on the PostgreSQL version — with the Sum and Avg aggregates. You can build your own Aggregates and place them, for example, on the app/aggregates.py module.

hmac performance measurement in python

published: 24-09-2011 / updated: 24-09-2011
posted in: development, programming, python, tips
by Daniel Molina Wegener

HMAC is a well known algorithm used in authentication mechanisms. It uses message digest algorithms, such as MD5, SHA1 and SHA256. Python provides modules which allows you to create HMAC shadowed passwords to be used in your applications. The implementation is based on hashlib and hmac, and both modules are using the OpenSSL library wrapped in Python using the Python C/API. I’ve measured the behaviour of those algorithms in a threaded environment, to let me know which one is the more convenient to be used in sites without creating heavy CPU loads when creating user accounts in batch processes, since we are using a VPS which is handles its costs based on resource usage.

inotify and python

published: 14-08-2011 / updated: 14-08-2011
posted in: development, programming, python, tips
by Daniel Molina Wegener

As you know Linux provides the inotify(7) API to monitor file system events using a convenient system calls that allows you to retrieve information about file system changes. The system calls that provides that API are implemented in a wide variety of high level programming languages, such as Python, Perl, and others. The Python implementation to wrap those calls has at least three variants, so I will review each of them in this article.