Skip to content

Instantly share code, notes, and snippets.

View stephane's full-sized avatar
🎯
Focusing

Stéphane Raimbault stephane

🎯
Focusing
View GitHub Profile
{% macro field_label(field) -%}
<label class="form-label" for="{{ field.id }}">
{{ field.label.text }} {% if field.flags.required %}*{% endif %}
</label>
{%- endmacro %}
{% macro field(field, group_class=None, space_field_class="") -%}
<div class="form-group{% if group_class %} {{ group_class}}{% endif %}">
{{ field_label(field) }}
{% if field.errors %}
@stephane
stephane / .docker_ignore
Last active September 7, 2021 20:47
Docker file for Poetry
.git
__pycache__
app/static
@stephane
stephane / gist:da4901064c269e176c5b0a4d9acd770c
Created January 18, 2021 22:49
To run a big-endian system
# Doesn't work anymore
docker run -it —-rm —-privileged multiarch/qemu-user-static —-credential yes —-persistent yes
docker run -it —-rm s390x/ubuntu bash
# works
sudo pacman -S qemu qemu-extras
curl -O https://people.debian.org/~aurel32/qemu/powerpc/debian_wheezy_powerpc_standard.qcow2
qemu-system-ppc -hda debian_wheezy_powerpc_standard.qcow2
@stephane
stephane / README.md
Last active April 9, 2020 21:19 — forked from larsenmtl/README.md
d3 mouseover multi-line chart

An interactive multi-line chart.

Note, I borrowed a bit of code from Duopixel's excellent code sample here.

Upgraded to D3v5.

@stephane
stephane / mappers.py
Created March 23, 2017 14:01
django-db-multitenant simple mapper example for PostgreSQL
"""Maps a request to a tenant using the first part of the hostname.
For example:
foo.example.com:8000 -> foo
bar.baz.example.com -> bar
This is a simple example; you should probably verify tenant names
are valid against a whitelist before returning them, since the returned
tenant name will be issued in a `SET search_path TO` SQL query.
@stephane
stephane / admin.py
Created August 26, 2015 20:22
How to override the widget of a field in the administration of Django
class IssueAdminForm(forms.ModelForm):
class Meta:
model = app_models.Issue
fields = ['title', 'labels']
widgets = {
'labels': app_forms.ArrayFieldSelectMultiple(
choices=app_models.Issue.LABEL_CHOICES),
}
class IssueAdmin(admin.ModelAdmin):
@stephane
stephane / forms.py
Last active April 8, 2021 08:10
Widget to render ArrayField in Django. Written by Brad Montgomery.
from django.utils.datastructures import MultiValueDict
class ArrayFieldSelectMultiple(forms.SelectMultiple):
"""This is a Form Widget for use with a Postgres ArrayField. It implements
a multi-select interface that can be given a set of `choices`.
You can provide a `delimiter` keyword argument to specify the delimeter used.
"""
def __init__(self, *args, **kwargs):
# Accept a `delimiter` argument, and grab it (defaulting to a comma)
@stephane
stephane / models.py
Last active August 26, 2015 20:23
ArrayField in Django 1.8
class Issue(models.Model):
LABEL_CHOICES = (
('bug', "Bug"),
('feature', "Feature"),
('blocker', "Release blocker"),
)
title = models.CharField(max_length=256)
labels = ArrayField(
models.CharField(max_length=32, choices=LABEL_CHOICES),
default=[], blank=True)
@stephane
stephane / models.py
Last active August 26, 2015 20:05
Django - Many to many with fixed list of choices
class Issue(models.Model):
title = models.CharField(max_length=256)
class Label(models.Model):
issue = models.ForeignKey(Issue, related_name='labels')
NAME_CHOICES = (
('bug', "Bug"),
('feature', "Feature"),
('blocker', "Release blocker"),
)
@stephane
stephane / gist:19fddde21391ea2d42f3
Created February 25, 2015 17:41
To rename and delete buffer/file
(defun rename-this-buffer-and-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))