Skip to content

Instantly share code, notes, and snippets.

@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 / profiling_qcachegrind.sh
Last active February 10, 2024 07:53
Python profiling with QCacheGrind
# Profile with cProfile python module and save to output
python -m cProfile -o output.cprof script.py
# Transform into tree format for QCacheGrind
pyprof2calltree -i output.cprof -o callgrind.cprof
# Open QCacheGrind and load callgrind.cprof file
@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 / 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 / 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 / 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 / numpy_lru_cache.md
Last active October 26, 2023 16:10
Make function of numpy array cacheable

How to cache slow functions with numpy.array as function parameter on Python

TL;DR

from numpy_lru_cache_decorator import np_cache

@np_cache()
def function(array):
 ...
@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)
@Susensio
Susensio / property_inheritance.md
Last active April 19, 2024 00:42
Inherit property setter in python 3.7

Python @property inheritance the right way

Given a Parent class with value property, Child can inherit and overload the property while accessing Parent property getter and setter.

Although we could just reimplement the Child.value property logic completely without using Parent.value whatsover, this would violate the DRY principle and, more important, it wouldn't allow for proper multiple inheritance (as show in the example property_inheritance.py bellow).

Two options:

  • Child redefines value property completely, both getter and setter.