Skip to content

Instantly share code, notes, and snippets.

@lucgiffon
lucgiffon / deprecated.py
Last active November 29, 2018 23:55
deprecated decorator
import warnings
def deprecated(msg=""):
def inner(func):
"""
This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.
def mpl_layout(rows_cols, axis=0):
"""
Description:
------------
Prepare matplotlib layout for complexe layouts.
Exemple:
--------
If you have done 6 independant experiences with graphes but you want to show them all in one figure with 2 graphes on each row
and 3 rows of graphes. Moreover, you want to display the graphes by lines, eg: on each row, you want 2 consecutive experiences.
def singleton(cls):
"""
Simple singleton implementation.
Usage:
@singleton
class A:
pass
@lucgiffon
lucgiffon / singleton.py
Created May 3, 2017 08:16 — forked from lambdalisue/singleton.py
Singleton Mixin Class of Python
#!/usr/bin/env python
# vim: set fileencoding=utf8 :
"""Singleton Mixin"""
class Singleton(object):
"""Singleton Mixin Class
Inherit this class and make the subclass Singleton.
Usage:
@lucgiffon
lucgiffon / dis_warns.py
Created April 27, 2017 13:59
piece pf cpde that disable warnings
def warn(*args, **kwargs):
pass
import warnings
warnings.warn = warn
@lucgiffon
lucgiffon / main.py
Last active April 18, 2017 21:23
Evolution du pourcentage de vote en fonction du pourcentage total de vote utile gagné par macron
from collections import OrderedDict
import numpy as np
import matplotlib.pyplot as plt
from pprint import pprint
# data source : https://fr.wikipedia.org/wiki/Liste_de_sondages_sur_l%27%C3%A9lection_pr%C3%A9sidentielle_fran%C3%A7aise_de_2017#Avril_2017
scores_fillon = [
19.5,
18.5,
21,
19,
@lucgiffon
lucgiffon / storebyext.sh
Last active April 14, 2017 21:46
Store the files in current directory with respect to their extensions if they have
search_dir='.'
for entry in "$search_dir"/*; do
# entry = la/bas/truc.zip
filename=$(basename "$entry")
# filename = truc.zip
extension=$([[ "$filename" = *.* ]] && echo "${filename##*.}" || echo '')
# extension = zip
re_nbr='^[0-9]+$'
if ! [[ $extension =~ $re_nbr ]] && ! [[ -z "$extension" ]] ; then
if ! [[ -d "$extension" ]] ; then