Skip to content

Instantly share code, notes, and snippets.

View Lucaterre's full-sized avatar
📚

Lucas Terriel Lucaterre

📚
View GitHub Profile
@Lucaterre
Lucaterre / AD_SCRAP_IMAGES.md
Last active February 20, 2023 10:36
Generic script to scrap & download images (exemple from AD)

Scrap @ download images (eg. from AD)

Quickstart

  1. Create a virtualenv
$ virtualenv -p python3.8 venv
@Lucaterre
Lucaterre / rapid_db_interface.py
Last active July 27, 2021 09:19
Rapid CRUD (Create Read Update Delete) class for Sqlite3/SQLAlachemy ORM database (Flask context)
import datetime
from app import db
# from models.data_schema import ...
class Database:
"""CRUD (Create Read Update Delete) Interface
for Sqlite3/SQLAlachemy ORM database"""
def __init__(self, database):
self.conn = database
@Lucaterre
Lucaterre / progressera.sh
Created June 17, 2020 19:30
To make a progress bar in bash
prog() {
local w=80 p=$1; shift
# create a string of spaces, then change them to dots
printf -v dots "%*s" "$(( $p*$w/100 ))" ""; dots=${dots// /.};
# print those dots on a fixed-width space plus the percentage etc.
printf "\r\e[K|%-*s| %3d %% %s" "$w" "$dots" "$p" "$*";
}
# Test loop
@Lucaterre
Lucaterre / clean_text.py
Created June 11, 2020 10:27
preprocessing cleaning text data module
def clean_text(text):
"""
performs a few cleanning steps to remove non-alphabetic characters
:param text:
:return:
"""
# replace new line and carriage return with space
text = text.replace("\n", " ").replace("\r", " ")
@Lucaterre
Lucaterre / surgery.py
Created June 9, 2020 10:26
intervertir des élements dans une liste suivant l'index et la parité
def surgery(liste):
if len(liste) % 2 == 0 and len(liste) != 0:
liste[0], liste[1] = liste[1], liste[0]
elif len(liste) % 2 != 0 and len(liste) != 0:
dernier = len(liste) - 1
avant = len(liste) - 2
liste[dernier], liste[avant] = liste[avant], liste[dernier]
else:
liste
return liste
def counter(in_filename, out_filename):
f1 = open(in_filename, 'r', encoding='utf8')
with open(out_filename, 'w', encoding='utf8') as out_f:
for position, line in enumerate(f1):
position += 1
# >> position (int) : number of words (int) : number of letters (int) : line (str)
out_f.write(f"{position}:{len(line.split())}:{len(line)}:{line}")
f1.close
from termcolor import colored
liste = [1, 4, 7, 0.4]
for i in liste:
if max(liste) == i:
print(colored(i, 'green'))
elif min(liste) == i:
@Lucaterre
Lucaterre / extract_exif.py
Created May 26, 2020 09:10
Module d'extraction des métadonnées exif
from PIL import Image, ExifTags
# ici on charge l'image
img = Image.open("./Datatest_img/FRAN_0025_0567_L.jpg")
print(dir(img))
# [... 'getexif' ...]
img_exif = img.getexif()
@Lucaterre
Lucaterre / validator_rng.py
Last active October 25, 2020 11:08
Linter RelaxNG pour source XML
from lxml import etree as ET
import sys
from termcolor import colored
def validator_rng(source_xml, schema_rng):
""" a little program to validate a xml source
with a RelaxNG schema
:param source_xml: source xml name to validate
:type source_xml: str
:param schema_rng: RNG schema for validate