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 with neutral element
and an the operation
, where the triple
denotes the Monoid. In terms of Category Theory, the set should be a category and the operation should be a morphism.
web developer & system programmer
coder . cl
ramblings and rants on software development...
re: monoids in python
by Daniel Molina Wegener on 2011.10.12posted in: development, programming, python, tips
custom aggregates on django
by Daniel Molina Wegener on 2011.09.28posted in: development, programming, python, tips
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
by Daniel Molina Wegener on 2011.09.24posted in: development, programming, python, tips
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
by Daniel Molina Wegener on 2011.08.14posted in: development, programming, python, tips
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.
integrating pycheckers and emacs
by Daniel Molina Wegener on 2011.08.09posted in: development, emacs, programming, python, tips
There are many versions of the pycheckers.py script. It is wrapper between various static analysis tools for Python code. I have my own modified version of the pycheckers script and it is running pep8, pychecker, pyflakes and pylint. I have that script integrated with Emacs, so I run the compile command to verify the code quality. My code should meet all Python standards to pass all checks that are made by those tools.



