Skip to content

Instantly share code, notes, and snippets.

View JPFrancoia's full-sized avatar

JPFrancoia JPFrancoia

View GitHub Profile
@JPFrancoia
JPFrancoia / fread.py
Last active June 24, 2018 10:54
Equivalent to Matlab fread function
def fread(fid, nelements, dtype):
"""Equivalent to Matlab fread function"""
if dtype is np.str:
dt = np.uint8 # WARNING: assuming 8-bit ASCII for np.str!
else:
dt = dtype
data_array = np.fromfile(fid, dt, nelements)
@JPFrancoia
JPFrancoia / strip_tags.py
Last active August 3, 2017 14:52
Strip html tags
def strip_tags(input_str):
"""Returns the string without the html tags"""
return re.sub('<[^>]*>', '', input_str)
@JPFrancoia
JPFrancoia / frange.py
Created August 3, 2017 14:51
Frange: range function with floats increment
def frange(start, end=None, inc=None):
"A range function, that does accept float increments..."
if end == None:
end = start + 0.0
start = 0.0
if inc == None:
inc = 1.0
def simpleChar(chaine):
"""Fct retournant la version minuscule et sans accent de la chaine
entrante"""
#http://www.siteduzero.com/forum-83-810635-p1-sqlite-recherche-avec-like-insensible-a-la-casse.html#r7767300
# Nouvelle fct de renommage, qui prend aussi les chiffres
#http://stackoverflow.com/questions/5574042/string-slugification-in-python
chaine = unidecode.unidecode(chaine).lower()
return re.sub(r'\W+', ' ', chaine)
@JPFrancoia
JPFrancoia / sizeof.py
Last active August 3, 2017 14:50
Sizeof
def sizeof(nbr, unit="o", rounded=1):
"""On récupère la taille en octets, et on la formate en Mo
ou en Go si plus grand que 1000 Mo. Si on passe l'argument 'b'
en paramètre, on calcule en ibytes"""
# http://www.fevrierdorian.com/blog/post/2011/06/26/Taille-d-un-fichier-humainement-comprehensible-en-Python
if unit == "o":
if nbr < 1000.0: