Skip to content

Instantly share code, notes, and snippets.

View twidi's full-sized avatar
🕶️

Stéphane "Twidi" Angel twidi

🕶️
View GitHub Profile
@twidi
twidi / pyproject.toml
Created November 10, 2023 11:49
config mypy pour wisemap
# ...
[tool.mypy]
plugins = [
"mypy_django_plugin.main",
]
python_version = "3.10"
check_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
@twidi
twidi / drf_utils.py
Created December 21, 2016 14:34
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
@twidi
twidi / ._README.md
Last active April 10, 2023 06:24
Pycharm and virtualenvwrapper, with postactivate

The problem

PyCharm has support for virtual environment.

But there are two problems:

  1. the virtual environment is not activated in the terminal (it is only in the python console)
  2. it doesn't support virtualenvwrapper and so doesn't run the postactivate file.

This gist is the solution I found to resolve these two problems.

@twidi
twidi / score.sql
Last active September 16, 2022 23:07
Swoosh? Boink! (scoring)
CREATE OR REPLACE FUNCTION pg_temp.get_scores(skip_days int) RETURNS TABLE (
"user" varchar(60),
first_game_id int,
nb_games int,
first_game_day date,
nb_played_days int,
nb_expected_days int,
nb_missing_days int,
final_score float,
regularity_factor float,
@twidi
twidi / linear-git-to-git-flow.sh
Created December 11, 2010 17:40
A script to transform a linear flow in a git repository (all in master) in a flow named "git-flow" (http://nvie.com/posts/a-successful-git-branching-model/) with a master branch, a develop one, and one for each feature, hotfixe and release.
#!/bin/bash
# Explanations : http://bit.ly/gs2qpL
# give optionnaly a revision from where to start
# if not given initial_ref will be the first ref available
initial_ref='757794e524755d2eebc6d881fea026c308a11fd5'
# declare below all the steps whith this format :
# 'version type name ref' \
@twidi
twidi / README.TXT
Created August 9, 2012 14:59
One key to toggle sidebar AND miniap in sublime-text-2
A simple way to toggle the display of the sidebar AND the minimap, with only one key binding.
Put "toggle_sidebar_and_minimap.py" in ~/.config/sublime-text-2/Packages/
and the content of "keymap" in your "Key bindings - User" file.
@twidi
twidi / README
Last active June 13, 2018 12:50
Run tests for code example in README.rst (for django)
# Real name of this file is README.rst but I don't want github to render the rst ;)
Blah blah blah
.. testsetup::
# This prepare the django environment to run all the "testcode" in this file
# This is not visible in the rendered README
import os
@twidi
twidi / timelapse-plant-script.sh
Created September 16, 2016 10:02
Script used to update each image for my plant timelapse https://www.youtube.com/watch?v=_WLxC3imytk
#! /bin/bash
# This script expect a image file as first argument, and a destination directory as second.
# It will:
# - rotate the image 0.4deg
# - crop to a ratio for HD (1920*1080)
# - add the timestamp in the top right corner
# This timestamp is in the format "xXh yYm", and computed from a time of the day extracted from the first image
# of the directory. All images are the same day, so it's easier.
# It's printed in white with a soft black shadow.
@twidi
twidi / clean_sky.py
Created September 14, 2016 21:44
Timelapse preparation: remove the birds and planes from the sky
# Clean the sky: remove birds, planes... only work if each images are "close", and there is no cloud moving fast
# by @twidi
import glob, os, shutil, sys
from gimpfu import *
def run(source_dir='.', extension='JPG', threshold=30, mask=None, dest_dir=None):
"""
@twidi
twidi / series.md
Last active August 15, 2016 14:46
series a voir
  • 24
  • Battlestar Galactica
  • Black Sails
  • Breaking Bad
  • Broadchurch
  • Bron/Broen
  • Community
  • Daredevil
  • Dead Like Me
  • Death Note