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 / test_schema.py
Created May 21, 2024 23:45
A pytest test used to learn using 'schema' library to validate JSON structure
"""
This is a demonstration and tutorial for "schema" library until its implementation is
finished since library documentation is painful to understand.
Schema validate data values and possibly coerces them if instructed to do so.
Basically schema respect given scheme structure. A callable item (like list or dict) is
followed recursively, a type object (like int or str) expect a value in this right type
and almost everything (like "foo" or 42) else is assumed as an exact value expected.
@sveetch
sveetch / video_infos.py
Created May 5, 2024 19:54
Collecting video meta informations with MediaInfo
"""
Proof of concept script to use MediaInfo to get metadatas from a video file.
Although this script have been done only for videos, MediaInfo also allow to read infos from audio and images.
First, this have been done with Python 3.10 but it should probably work with Python 3.8
MediaInfo library is required to be installed on your system, see:
https://github.com/MediaArea/MediaInfo
@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: ::