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

Use the same function as context manager and decorator

Posted on 2022-09-25 in Trucs et astuces • Tagged with Python

I recently learned that context managers created with @contextmanager can be used either as a context manager or a decorator:

from contextlib import contextmanager

@contextmanager
def test_context():
    print('Entering')
    yield
    print('Leaving')

with test_context():
    print('Inside')

@test_context()
def test_decorated():
    print('Decorated')

test_decorated()

We will yield:

Entering
Inside
Leaving

Entering
Decorated …

Continue reading

React hook to load fonts

Posted on 2022-06-11 in Trucs et astuces • Tagged with JavaScript, React

If you need to load a specific font in a component, you can use this hook. It will return true when the fonts are loaded. It relies on the document.fonts API to load the fonts. If the fonts are already loaded, the promise will be fulfilled immediately and the …


Continue reading

How to avoid CSRF token issues with Django when running on different sub-domains

Posted on 2022-02-13 in Trucs et astuces • Tagged with Python, Django

If you deploy multiple Django websites on your infrastructure on various subdomains, you may get issues about invalid CSRF tokens. This is happening either because:

  • You erase the cookie by using the same domain. For instance, if you have your prod API at api.jujens.eu and pre-production one at …

Continue reading

Check domains

Posted on 2021-09-22 in Trucs et astuces

Here is a small script to allow you to easily check that a domain your manage is correct (ie responds correctly, is available with IPv4 and IPv6, only supports TLS 1.2+…). It even has some color built in! You can of course adapt it to fit your needs.

You …


Continue reading

Small security checklist for public backend services

Posted on 2021-09-19 in Trucs et astuces • Tagged with security

Here are some security tips to check for backend services. It's mostly meant so that I can have a check list. So I don't develop them much but provide extra links where necessary. I also probably expand this list as time goes one and I learn more about this subject …


Continue reading

Manage deployment transitions for static application

Posted on 2021-04-25 in Trucs et astuces • Tagged with Docker, Kubernetes

When you deploy a frontend app, most of the time the name of your assets contains their hash so you can easily cache the files. So instead of just having main.js you will have something like main.1234.js. The problem is that your HTML will reference main.1234 …


Continue reading

Using DateTimeRangeField in Django

Posted on 2021-04-06 in Trucs et astuces

:tags:Django, Python, PostgreSQL :lang: en

The basics

If you need to store a datetime range in Django (for instance from which day to which day a listing is valid), instead of relying on two fields like valid_from and valid_to, you can use a single field validity_range of type DateRangeField …


Continue reading

Deploy a React app in kuberentes

Posted on 2021-04-01 in Trucs et astuces • Tagged with devops, k8s, kubernetes, Django, Python

I recently deployed a React app in kubernetes. It was initially deployed directly in a public bucket: I have an API that is already hosted on kubernetes, but the app itself is made only of static files, so it made sense. However, requirements for my app changed and I required …


Continue reading