Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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:
def singleton(cls):
"""
Simple singleton implementation.
Usage:
@singleton
class A:
pass
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.
@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.
@lucgiffon
lucgiffon / gist:f874c43a0c25ff89ac17611c41cefbb0
Created June 29, 2017 08:42 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
'''
Implementation of Fastfood (Le, Sarlos, and Smola, ICML 2013).
Primarily by @esc (Valentin Haenel) and felixmaximilian
from https://github.com/scikit-learn/scikit-learn/pull/3665.
Modified by @dougalsutherland.
FHT implementation was "inspired by" https://github.com/nbarbey/fht.
'''
@lucgiffon
lucgiffon / mnist.py
Created November 29, 2017 17:38 — forked from akesling/mnist.py
import os
import struct
import numpy as np
"""
Loosely inspired by http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py
which is GPL licensed.
"""
def read(dataset = "training", path = "."):