Commenting the code

I always find surprising to find out comments like that regarding code comment. I can understand that someone argues about that writing comments on the code is boring, or that you forget about it or whatever. But to say that the code shouldn’t be commented at all looks a little dangerous to me. That doesn’t mean that you’ll have to comment everything. Or that adding a comment it’s an excuse to not be clear directly on the code, or the comment should be repeat what is on the code. You’ll have to keep a… Read More

ORMs and threads

Do you remember the post from Joel Spolsky about leaking abstractions? It’s the kind of idea that, the first time I read, about it, was intrigued, but after some time, I began to see it on every place. There are from time to time some problems on my Python code (as well as in other high-level languages) that I am really glad to be able to have an idea of the underlaying low level C, or I will be struggling with some very weird, confusing problems. I have enough confusing and weird problems… Read More

Migrating data to a new db schema with Django 1.2

This week I had to make a migration of data on a database from an old schema to a new one. The database is part of a Ruby on Rails application, so the changes are part of new features, and we have also taken the opportunity to clean up a little the database and make some changes to be more flexible in the future. As we want to be consistent, we need to migrate all the old data to the new database. After talking with people with more experience than me on Rails… Read More

Presentation “Use of Django at Jolt Online” at Python Ireland

Yesterday I give a talk about the use of Django in my actual position at Jolt Online Gaming. on the Python Ireland group  I talked a little, using one recent system as example, about our production configuration, use of Django on non-typical ways, work with the database and other tools we use related. At least there were a lot of questions and comments and some great conversation afterwards, so I think it was interesting for the people attending… So there are the slides (in PDF), in case anyone want to take a… Read More

The intelligent solution that turns to be unadequate

Recenlty I asked for advice on StackOverflow with a question related to sorting information on a Django application. I copy the question here: I’m trying to do something similar to this, in Django. This is part of the page of Anna: Pos NickName      Points — ———     —— 1   The best      1000 … 35  Roger         550 36  Anna          545 37  Paul          540 It’s a chart showing the scoring system, and it intends to show… Read More

People really love RDBMSs

I had this discussion with a friend, helping him with a personal project. It was a software to help with a weekly schedule, so it has some teachers, each ones with a profile, some alumns, each one with a profile, and classes, relating the teachers with the alumns with time and physical place. My friend has deal work a lot with RBMS and as a DBA, mostly with Oracle and MySQL, and he his quite good at that. He began designing a relational database model, with tables for alumns, teachers, places, etc…… Read More

Travelling salesman

One classic computation problem, the travelling salesman. Even if it’s quite simple to describe, it’s one of those hideous NP complete problems, the ones that are quite difficult to resolve, as the computation time needed grows greatly with the length of the data. On Programming Praxis they have proposed to resolve the problem using brute force, and using the closest neighbor (a simplification of the problem). I’ve created this program, in Python. The time spend on each is brutally different, specially as the number of cities grow. With more than 9 cities,… Read More

Interesting Project Euler problem

There is one interesting problem to solve from the guys on Project Euler. I think that maybe there are some problems running a naive approach to the problem on the 2002, but right now, even a inefficient approach can give you results in not much time. I’ve made the following program in Python to measure the differences between a straight approach, and one using recursion and memoization. Looking carefully at the sequences, we realize that each time we get to a previous calculated number, we don’t have to recalculate the sequence again. So, doing… Read More

Deployment of Django project using CherryPy and Cherokee

Recently, we have deployed into a test production our latest Django project. Choosing which deployment to use it’s not easy, as there are a lot of different tools for the job, but as we expect some load on the system, we have been spending some time in getting a good deployment that will allow us to be confident on the grow of the system. After some research, we decided to use CherryPy and Cherokee. Why CherryPy? It’s pure Python, and easily integrated with Django. You can do it by yourself (it’s not very… Read More

Store standard output on a variable in Python

This is a great, hacky trick to get the standard output ( and others like standard error and standard input) in Python You can “redirect” the standard error changing the sys.stdout module with your own StringIO object. So, you can do something like Easy and very useful!   EDITED: Updated to make it work for Python 3.4