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 / 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
@sveetch
sveetch / smart_image_format.py
Last active February 27, 2020 01:58
Class mixin and template tags samples to implement naive image smart format detection
class SmartFormatMixin(object):
"""
A mixin to inherit from a model so it will have a common helper
methods to manage image formats.
"""
def media_format(self, mediafile):
"""
Common method to perform a naive check about image format using file
extension.
@sveetch
sveetch / parsing-foundation-breakpoint.py
Created June 30, 2019 00:16
Attempt to parse foundation breakpoints to compare them in pixels
"""
Attempt to parse breakpoints to compare them in pixels
"""
from collections import OrderedDict
base_font_size = 16
base_font_unit = "px"
@sveetch
sveetch / i18n.py
Last active June 30, 2019 00:11
Smart templatetag with translation and context driven from settings (save from an attempt on Richie)
"""
i18n utilities for our search app
"""
from django.conf import settings
def get_best_field_language(multilingual_field, best_language):
"""
Pick the best available language from a multilingual field.