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 / python_interfacing.py
Created October 19, 2017 04:45
This file performs some basic interfacing in Python 2, tested via unittest
"""This file performs some basic interfacing in Python 2:
1. Defining the methods that have to be overriden with the ABC module
2. Defining an input and output signature for those methods
3. Testing the validity of different implementations via unittest
Note the following:
!! In order to check the input/output signatures, the overriden methods have to be run once
at construction, which may be undesirable (usually this kind of interfacing happens within
a protocol that can take care of that).
"""
@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 / 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 / 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 / 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 / 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 / almat2almat.sc
Created May 8, 2020 12:37
ALMAT 2017 SuperCollider script
(//server config and start
Server.default = s; // = Server.internal;
s.options.memSize = 1500*1024;// up to 1500MB RAM allocable
s.reboot;
//s.quit;
)
(
//s.volume.gui;
//s.plotTree;
@andres-fr
andres-fr / commitizen_configless_bump.py
Last active November 1, 2020 20:31
A Config-less `cz bump`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
ATM commitizen just supports bumping via config file. Since we want a more
interactive approach, re-wrote the class with an explicit interface.
VRS=`python -c "from ml_lib import __version__ as v; print(v)"`
python ci_scripts/commitizen_bump.py -P ml_lib/_metadata.py -v $VRS --changelog
--dry_run
@andres-fr
andres-fr / neo4j_schema.py
Last active February 11, 2021 20:56
Neo4j Schema using py2neo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Self-contained script that exemplifies the implementation of a pseudo-schema
for Neo4j using py2neo. Specifically:
1. Defines some helper functions for typechecking and CRUD operations
2. Defines the base clase for the schema. Basically, it is a Node and