Skip to content

Instantly share code, notes, and snippets.

@Susensio
Susensio / sync_backlight.sh
Created July 28, 2018 09:15
Syncs laptop backligh to LG HDMI monitor
#!/usr/bin/env bash
# Listen for changes in backlight and applies to external screen
MAX_BACKLIGHT=$(</sys/class/backlight/intel_backlight/max_brightness)
last_backlight=$(</sys/class/backlight/intel_backlight/brightness)
acpi_listen | while IFS='/' read -ra line; do
if [ "$line" = "video" ]; then
# Read laptop backlight
sleep 0.2
@Susensio
Susensio / __init__.py
Last active August 2, 2018 07:54
Python logging boilerplate for packages
from .module import foo
import logging
from logging.handlers import RotatingFileHandler
import os
import os.path
# Logging directory
LOGGING_FOLDER = 'logs/'
LOG_PATH_TEMPLATE = LOGGING_FOLDER + "{}.log"
@Susensio
Susensio / HumbleBundle books.md
Last active August 29, 2018 10:32 — forked from santiagobasulto/README.md
Download HumbleBundle books in batch with a simple Python script.

Download HumbleBundle books

This is a quick Python script I wrote to download HumbleBundle books in batch. I bought the amazing Machine Learning by O'Reilly bundle. There were 15 books to download, with 3 different file formats per book. So I scratched a quick script to download all of them in batch.

(Final Result: books downloaded)

@Susensio
Susensio / open_terminal_shortcut.sh
Last active September 17, 2018 08:48
Add open terminal here shortcut in Debian 9.5 Gnome
# Source: https://askubuntu.com/questions/68078/keyboard-shortcut-for-open-a-terminal-here
echo "#! /bin/sh
gnome-terminal" > ~/.local/share/nautilus/scripts/Terminal
chmod +x ~/.local/share/nautilus/scripts/Terminal
# F12 or whatever
echo "F12 Terminal" > ~/.config/nautilus/scripts-accels
@Susensio
Susensio / rotation_spacing.py
Last active September 17, 2018 10:41 — forked from jsfenfen/output.png
Detecting rotation and line spacing of image of page of text using Radon transform
# -*- coding: utf-8 -*-
"""
Inspired in https://gist.github.com/jsfenfen/4c615775007b802117b7
Automatically detect rotation and line spacing of an image of text using
Fourier transforms
If image is rotated by the inverse of the output, the lines will be
horizontal (though they may be upside-down depending on the original image)
@Susensio
Susensio / dynamic_plotting.py
Created September 26, 2018 08:45 — forked from greydanus/dynamic_plotting.py
Dynamic plotting for matplotlib
"Dynamic plotting in matplotlib. Copy and paste into a Jupyter notebook."
# written October 2016 by Sam Greydanus
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import time
def plt_dynamic(x, y, ax, colors=['b']):
for color in colors:
ax.plot(x, y, color)
import shelve
from functools import wraps
def persistent_cache(cache_file='.cache'):
"""Using shelve module creates a cache that persists across executions.
Depends on repr giving a univocal representation of input arguments.
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
@Susensio
Susensio / git_push_active_branch.md
Last active January 11, 2019 09:18
First git push to remote

Disclaimer

This gist allows full control from the client, discarding all possible changes made in the server!

NOT USEFULL for colaborative work without further modifications. Coworkers commits could be deleted.


Server

Init server repository and configure

@Susensio
Susensio / static_variable_decorator.py
Created April 27, 2020 12:39
Python static variable decorator for functions
# Source: https://stackoverflow.com/questions/279561/what-is-the-python-equivalent-of-static-variables-inside-a-function/279586#279586
def static_vars(**kwargs):
def decorate(func):
for k in kwargs:
setattr(func, k, kwargs[k])
return func
return decorate
@Susensio
Susensio / DirRecursive.vba
Created February 3, 2022 10:38
Find paths in VBA with wilcard pattern in subdirectories, using DIR funcion
Public Function FindPathRecursive(StartFolder As String, Pattern As String, Optional SearchMode As VbFileAttribute = vbNormal) As String
' Función recursiva que permite buscar rutas con coincidencia de patrones, usando el widlcard comodín *
' Por ejemplo, permite buscar el archivo
' \\srvfs1\etiquetas\Bartender\Plantillas envase\UA_*\124755_*\L_Delantera.*
' con los parámetros
' StartFolder = "\\srvfs1\etiquetas\Bartender\Plantillas envase\"
' Pattern = "UA_*\124755_*\L_Delantera.*"
' devolviendo como resultado
' \\srvfs1\etiquetas\Bartender\Plantillas envase\UA_UCRANIA\124755_SPECTR-AGRO LLC\L_Delantera.btw
' en caso de no encontrar el archivo, devuelve un string vacío ""