Using super to reuse method with inheritance in Python

Posted on 2025-06-09 in Trucs et astuces • Tagged with Python

If you use Python, you probably already know of super to call a method from the base class. You probably also know you can use a function as a method if it takes the instance as 1st parameter. What you cannot do, is call super().my_method() directly in such a …


Continue reading

Using JavaScript and TypeScript in jupyter notebook

Posted on 2025-05-23 in Trucs et astuces • Tagged with Python, JavaScript, TypeScript

While wandering how to run some tests with JavaScript, I discorvered that deno, a JavaScript runtime like NodeJS, has support for jupyter notebooks thanks to this article. It works perfectly. Install deno (probably available in your distribution repositories), run deno jupyter --install and you are good to go!

To get …


Continue reading

Reusing Pydantic validators and serializers

Posted on 2025-04-21 in Trucs et astuces • Tagged with Python, Pydantic

I’ll give some tips to reuse field and model validators and serializers. All my examples will use validators, but it works exactly the same for serializers.

Field validators

Assign the validator to a variable like so:

def _is_above_ten(value: int):
    if value > 10:
        return value

    raise ValueError(f"{value …

Continue reading

Converting jupyter notebooks

Posted on 2025-04-17 in Trucs et astuces • Tagged with Python

You can export a notebook directly from the interface under File > Save and Export Notebook As. You can also do it in CLI with:

jupyter nbconvert --execute --to <FORMAT> my_notebook.ipynb

The --execute will execute the notebook to make sure all output cells are up to date. Many export formats …


Continue reading

Sending all nginx logs to journald

Posted on 2025-04-13 in Trucs et astuces • Tagged with systemctl, Linux

As part of my work to uniformize my server setup around systemd, I decided to make nginx log everything with journald. By default, it logs accesses and errors in log files under /var/log/nginx. I already had one log file per vhost.

To do the change, I changed my …


Continue reading

PostgreSQL using ANY instead of IN

Posted on 2025-03-31 in Trucs et astuces • Tagged with PostgreSQL, Database

I recently learned while reading psycopg’s documentation (a Python driver for PostgreSQL), that you should use WHERE id = ANY(:values) instead of WHERE id IN :values when filtering over lists. That’s because the ANY operator works with empty list while IN doesn’t. Psycopg will also correctly adapt …


Continue reading

Monitor certificates statuses

Posted on 2025-03-30 in Trucs et astuces

Let’s encrypt recently announced they will stop sending emails when certificates must be renewed. Following this announcement, I created a small script to monitor the status of my certificates and receive an email if they are not renewed in time. Since it can be handy, here it is!

The …


Continue reading

Execute Python scripts over SSH without copying them

Posted on 2025-01-05 in Trucs et astuces • Tagged with SSH, Linux

You can run scripts (written in Python or any other language) directly on a server if the proper interpreter is installed. I recently used it to run a Python script over several servers without the need to copy the relevant script on the server. It all relies on the following …


Continue reading

Ignore commits in git blame

Posted on 2023-12-02 in Trucs et astuces • Tagged with git

Commits that change formatting are a pain in git because they make using git blame much harder. It turns out, you can ask git to ignore these commits when running git blame with the --ignore-rev option and passing it a commit hash. You can even do things better and create …


Continue reading

Some cool type tips in TypeScript

Posted on 2023-08-17 in Trucs et astuces • Tagged with TypeScript

Here is an unsorted type tips I find useful in TypeScript. I may update it when I find new ones. Don't hesitate to share yours in the comments!

Another good start, is to read this page from the handbook which list various builtin utility types. If you are really motivated …


Continue reading