Skip to content

Instantly share code, notes, and snippets.

View sveetch's full-sized avatar
🥝
I'm a kiwi

David THENON sveetch

🥝
I'm a kiwi
View GitHub Profile
@sveetch
sveetch / cat_tag_tracker.rst
Created October 22, 2023 20:37
Cat tag tracker

Cat tag tracker

But

Le but ici est de produire un périphérique pour détecter la présence d'une puce RFID à longue distance (minimum 30cm) et qui soit capable d'envoyer l'information à un

@sveetch
sveetch / python_encoding_quickcheat.txt
Created September 25, 2023 01:11
A simple reminder quickcheat about Python encoding and decoding with string and bytes
In Python 3, this mental model is pretty straight-forward:
Encoding is the process of converting a str to a bytes object
Decoding is the process of converting a bytes object to a str
┏━━━━━━━┓ ┏━━━━━━━┓
┃ ┃ -> encoding -> ┃ ┃
┃ str ┃ ┃ bytes ┃
@sveetch
sveetch / build_requirements.py
Created September 24, 2023 14:56
Build requirements file content from requirements collected from a package metadata with support of extras (optional requirements).
"""
This requires ``Python>=3.8`` and ``packaging>=23.1``.
"""
from importlib.metadata import requires
from pathlib import Path
from packaging.requirements import Requirement
class RequirementBuilder:
@sveetch
sveetch / Makefile
Last active October 29, 2023 15:17
A simple parser to collect all task help description from a Makefile
help:
@echo "Please use 'make <target> [<target>...]' where <target> is one of"
@echo
@echo " Cleaning"
@echo " ========"
@echo
@echo " clean -- to clean EVERYTHING"
@echo
@sveetch
sveetch / 000_bigtree_issue_sample.py
Last active August 12, 2023 11:12
Test suite for a 'bigtree' library issue
"""
A test suite use for research&development and that demonstrate an issue with
'dict_to_tree'
It has been started with custom Node object sample:
https://bigtree.readthedocs.io/en/latest/others/tips.html#population-node-add-functionality-method-property
Opposed to original sample the percentage attribute have been disabled else it causes
"division by zero" and prevent to make demonstration.
@sveetch
sveetch / test_view_form.html
Last active April 8, 2023 23:59
A demonstration of basic view, form and field tests with Pytest and django-pytest. For easiness, everything is in the test file except the template which you will need to put into your template directory.
<form action="/sample/" method="post">
{% csrf_token %}
{% if form.non_field_errors %}{% spaceless %}
<div class="non_field_errors">{{ form.non_field_errors }}</div>
{% endspaceless %}{% endif %}
{% for field in form %}
<div class="{{ field.html_name }}__container">
{% for error in field.errors %}
@sveetch
sveetch / admin.py
Created January 15, 2023 17:08
Sample admin filter hack to customize choices
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from ..choices import get_language_choices, get_language_default
class DeprecatedLanguageListFilter(admin.SimpleListFilter):
"""
Add Human-readable language title as defined in LANGUAGES setting.
@sveetch
sveetch / extended_jsonencoder.py
Last active December 2, 2022 02:23
Extended JSON encoder for additional Python builtins
import datetime
import json
from pathlib import Path
class ExtendedJsonEncoder(json.JSONEncoder):
"""
Additional opiniated support for more basic object types.
Usage sample: ::
@sveetch
sveetch / dr_eggs.py
Last active September 16, 2021 23:45
A script to extract installed packages versions from a Buildout project
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
A script to extract installed packages versions from a Buildout project.
Install
*******
This is a "one man army" script without specific requirements. Just drop the file in
your project and use it.
@sveetch
sveetch / renamer.py
Last active October 28, 2021 10:15
Filename renamer
"""
Command line script to rename media files.
Prerequisite:
* Python >= 3.6;
* Unicode and Emoji fonts enabled in your terminal console;
"""
import json