Skip to content

Instantly share code, notes, and snippets.

View andres-fr's full-sized avatar

Andres Fernandez andres-fr

View GitHub Profile
@andres-fr
andres-fr / array_masker.py
Created January 15, 2020 18:03
A Python3 script to mask arrays by customizable criteria (e.g. color spheres)
# -*- coding:utf-8 -*-
"""
This script deals with extracting value-based masks from images in various ways.
At some point it might be sensible to use OpenCV to scale further up.
https://www.learnopencv.com/tag/inrange/
Explanation of PIL HSV space:
https://pillow.readthedocs.io/en/latest/reference/ImageColor.html?highlight=hsv#color-names
@andres-fr
andres-fr / python_interfacing_ioc.py
Last active October 2, 2019 15:25
Proper interfacing in Python
# -*- coding:utf-8 -*-
"""
Python's duck typing system allows for very pleasant prototyping. But at some
point, it is convenient to enforce some interfacing. This can be achieved
Through abstract base classes and annotations to a great extent.
Another approach is to use dependency injection and inversion of control
patterns. This gist exemplifies how to do that using ``dependency_injector``.
@andres-fr
andres-fr / emacs-tweaks.el
Last active October 3, 2019 04:10
Some custom tweaks to apply on the top of a proper config
(defun kill-all-buffers ()
(interactive)
(mapc 'kill-buffer (buffer-list)))
(defun simple-backtick ()
(interactive)
(insert "``")
(backward-char 1))
(defun double-backtick ()
@andres-fr
andres-fr / exr_to_np.py
Created September 19, 2019 20:26
Convert EXR files to numpy float32 matrices
# -*- coding:utf-8 -*-
"""
Place this script on a directory and convert the .exr files it contains
into np.float32 matrices
"""
import os
import OpenEXR
@andres-fr
andres-fr / graphkit_utest.py
Last active September 19, 2019 05:15
Python3 unittest suite for the graphkit library (https://github.com/yahoo/graphkit)
# -*- coding:utf-8 -*-
"""
This module contains test cases regarding usage of Yahoo's ``graphkit``
library for DAG-based computation: https://github.com/yahoo/graphkit
"""
import unittest
@andres-fr
andres-fr / py3_color_logger.py
Last active October 15, 2023 01:06
A well-suported and pre-configured color logger for Python 3
#!/usr/bin python
# -*- coding:utf-8 -*-
"""
This module features convenient color logger (wrapping the built-in ``loging.``
class), plus some helper functionality.
"""
@andres-fr
andres-fr / find_subwav.py
Last active June 8, 2019 13:22
Given 2 mono wavs, finds out if one is a chunk of the other and returns the positions with sample precision. Includes a test.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Given the paths to 2 wav audio files, this script tells whether one is a subset
of the other, and in which range.
Usage help:
python <THIS_SCRIPT> -h
"""
@andres-fr
andres-fr / flask__server__client.py
Last active June 25, 2023 18:41
Flask client/server to exchange compressed numpy arrays:
################################################################################
### server.py
################################################################################
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Dummy server, interacts with the client receiving, altering and returning
@andres-fr
andres-fr / bash_hash_map.sh
Created February 8, 2018 11:23
A simple example of defining and iterating over a hash map in bash4
declare -A table=(["2017_10_10_06_35_48"]="1507653643855 1507653618853 1507653549538 1507653656449 1507653643683 1507653657262" ["2017_10_10_04_08_29"]="1507644652041 1507644656963 1507644746592 1507644767765 1507644803720 1507645191645 1507645193645" ["2017_09_14_12_10_46_Anita"]="1505384055344 1505384056438 1505384060281 1505384062750 1505384067126 1505384067313 1505384072126 1505384073001 1505384073376 1505384074032 1505384074157 1505384074626 1505384198554 1505384226587 1505384228774 1505384257776 1505384260854 1505384260979 1505384267432" ["2017_09_14_12_19_08_Nida_aufs_Dach"]="1505384352176 1505384352333 1505384352489 1505384365130 1505384376787 1505384397522 1505384397710 1505384398304 1505384401147 1505384405273" ["2017_10_25_02_08_30"]="1508933312919 1508933312966 1508933313013 1508933313075 1508933313200 1508933313263 1508934104162 1508934104209 1508934104272 1508934104334 1508934104397 1508934104459 1508934105444 1508934105490 1508934105553 1508934105615 1508934105678 1508934312548" ["2017_09_14_11
@andres-fr
andres-fr / overlap_save_convolver.cpp
Last active August 2, 2021 11:03
C++ spectral convolution of 1D signals (OpenMP+FFTW)
// OverlapSaveConvolver: A small C++11 single-file program that performs
// efficient 1D convolution and cross-correlation of two float arrays.
// Copyright (C) 2017 Andres Fernandez (https://github.com/andres-fr)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,