I use Python at work and for private projects. I also aim to write tests for my code, especially recently. And as I usually don’t start from 100% code coverage (TDD is not my game), I at least want to know if the code I just wrote have full coverage.
Articles under this tag
I’m in a team who are developing a Flask-based web application, which uses
logging extensively. For a while now it spews out a lot of lines so the
need arose to index them in ElasticSearch, and more importantly, to search
through them for auditing purposes. This latter user story brought up one
more question: why don’t we categorize our log messages? I quickly came up
with an extended log format (
[auth] is the new category name):
I have recently messed up my Alembic migrations while modifying my SQLAlchemy models. To start with, I didn’t update the auto-generated migration files to name the indexes/foreign keys a name, so Alembic used its own naming scheme. This is not an actual problem until you have to modify columns that have such constraints. I have since fixed this problem, but first I had to find which column references what (I had no indexes other than primary key back then, so I could go with foreign keys only). Here is a query I put together, mostly using this article.
When creating multilingual software, be it on the web, mobile, or desktop, you will eventually fail to mark strings as translatable. I know, I know, we developers are superhuman and never do that, but somehow I stopped trusting myself recently, so I came up with an idea.
Today I needed a function to create a slug (an ASCII-only representation of a string). I went Googling a bit, and found an excellend Flask snippet. Problem is, it is designed for Python 2, so I came up with a Python 3 version.
Now that I write Python code for a living, I write a lot of functions, classes, and modules. What I still tend to forget, and also find tedious, is adding docstrings. Unlike many developers, writing documentation is not an enemy of mine, but it usually comes to my mind when I finish implementation. The procedure, roughly, is this:
One thing I really miss from Django
made my life so much easier while developing with Symfony. In Django,
of course, there is
but, for example, in one of my projects I had a view that had to resolve 6(!)
objects from the URL, and writing
get_object_or_404 six times is not what a
programmer likes to do (yes, this view had a refactor later on). A quick Google
search gave me one usable
(in French), but it was very generalized that I cannot always use. Also, it was
using a middleware, which may introduce performance issues
sometimes. So I decided to go with decorators, and
at the end, I came up with this:
Gergely Polonkai is a systems engineer of a telco company, and also a freelancer self- and software developer.
He is learning about different IT subjects since the late 1990s. These include web development, application building, systems engineering, IT security and many others. He also dug his nose deeply into free software, dealing with different types of Linux and its applications, while also writing and contributing to some open source projects.
On this site he is writing posts about different stuff he faces during work (oh my, yet another IT solutions blog), hoping they can help others with their job, or just to get along with their brand new netbook that shipped with Linux.
“I believe one can only achieve success if they follow their own instincts and listen to, but not bend under others’ opinions. If you change your course just because someone says so, you are following their instincts, not yours.”