Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env python3
# coding: utf-8
#
# Module to generate the code of Netcdf4 Driver (Mbg...)
#
import ntpath
import netCDF4 as nc
@Aluriak
Aluriak / autoload_package_submodules.py
Last active July 20, 2021 09:52
Autoloading of a package submodules in python
def autoload_package_submodules(package:object, log_info:callable=print, log_error:callable=print):
"""Import all submodules of given package to have them loaded"""
import os, glob, importlib
path = os.path.split(package.__file__)[0]
pkg_name = package.__name__
for fname in glob.glob(os.path.join(path, '*.py')):
modname = os.path.splitext(os.path.split(fname)[1])[0]
if modname.startswith('_'): continue # ignore private modules
try:
@Aluriak
Aluriak / Makefile
Created July 9, 2021 14:49
Latonf: coordinates formatter helper, also working on csv files.
all:
python latonf.py example-data.csv 0 1 -f '%Ddeg %Mmn %Ssec %w'
pandas:
python latonf.py example-data.csv 0 1 -f '%Ddeg %Mmn %Ssec %w' -p
pandas-with-chunks:
python latonf.py example-data.csv 0 1 -f '%Ddeg %Mmn %Ssec %w' -c
test:
pytest latonf.py -v --doctest-modules
#!/usr/bin/python3
"""detect fail2ban's currently banned IP using its log file,
and show them in stdout
"""
import re
import argparse
from collections import defaultdict
@Aluriak
Aluriak / upload_to_local_seafile.py
Created June 10, 2020 22:23
Little helper to upload a file or a set of file in a library of a seafile instance.
#!/usr/bin/python3
"""Little helper to upload a file or a set of file in a library of a seafile instance,
using requests.
"""
import os
import glob
import json
import argparse
import getpass
"""What is the adress i should use ?"""
import itertools, random
ANSWER = 'Univ Rennes, Inria, CNRS, IRISA F-35000 Rennes'
NEEDED = {'Inria', 'Univ', 'CNRS'}
MAX_PROPOSITIONS = 6
@Aluriak
Aluriak / heatmap.py
Created March 27, 2019 10:21
Example of pandas/seaborn heatmap generation
"""Example of pandas/seaborn heatmap generation"""
import matplotlib.pyplot as plt
import pandas as pd
def heatmap_using_seaborn(data):
import seaborn as sns; sns.set()
ax = sns.heatmap(data)
plt.show()
@Aluriak
Aluriak / vsp.py
Last active January 25, 2019 23:24
Simulation of a spreading virus
"""Simple simulation of a virus spreading,
using numpy matrices for internal board representation,
and pillow to generate a colored gif visualization.
pip install numpy Pillow
python vsp.py
Outputs: vsp.gif
A cell of the 2D world is either None or an integer >= -2.
@Aluriak
Aluriak / gol.py
Created March 21, 2018 10:45
game of life with numpy and pillow
"""Simple (and slow) implementation of the game of life,
using numpy matrices for internal board representation,
and pillow to generate a gif visualization.
pip install numpy Pillow
python gol.py
Outputs: gol.gif
"""
@Aluriak
Aluriak / gif-writer.py
Created March 14, 2018 10:12
gif writer with pillow
"""Write a gif where a line moves horizontally.
Note that this code does not work with pillow 3.4.0
(only the first frame is written).
Tested with pillow 5.0.0.
"""
from PIL import Image