Skip to content

Instantly share code, notes, and snippets.

View iagoalonsomrf's full-sized avatar

Iago Alonso iagoalonsomrf

View GitHub Profile
@iagoalonsomrf
iagoalonsomrf / delete-merged-branch.sh
Created September 14, 2023 11:35
Delete your working branch after it's merged, and pull the default branch
#!/usr/bin/env bash
DEFAULT_BRANCH="master"
CURRENT_BRANCH=$(git branch --show-current)
if git checkout "$DEFAULT_BRANCH"
then
git pull
if ! git branch -d "$CURRENT_BRANCH"
then
@iagoalonsomrf
iagoalonsomrf / update-current-branch.sh
Last active September 14, 2023 11:38
Merge the default branch into yours, even if it's in a dirty state
#!/usr/bin/env bash
DEFAULT_BRANCH="master"
CURRENT_BRANCH=$(git branch --show-current)
git stash
git checkout "$DEFAULT_BRANCH"
git pull
git checkout "$CURRENT_BRANCH"
git merge "$DEFAULT_BRANCH"
@iagoalonsomrf
iagoalonsomrf / parse_ansible_ufw_rules_diff.py
Last active September 13, 2023 13:38
Parse Ansible's json output of an UFW rules change step.
import json
import os
import re
import tempfile
COMMENT_RE = r'(route\:allow|allow)\s(tcp|udp)\s([0-9]{1,4})\s((?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/[0-9]{1,2})[\sa-zA-Z]+((?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)\.?\b){4})' # noqa: E501
def get_diff(data):
diff_object = data['results'][2]['diff'][0]
#!/usr/bin/env bash
read -p "Set scaling governor to: " GOVERNOR
if [ "$GOVERNOR" == "performance" ] || [ "$GOVERNOR" == "powersave" ]
then
for i in {0..11}; do echo "$GOVERNOR" | sudo tee /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor; done
else
echo "Value $GOVERNOR is not a valid scaling governor"
fi
import re
COMMENT_RE = r'(route\:allow|allow)\s(tcp|udp)\s([0-9]{1,4})\s((?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/[0-9]{1,2})[\sa-zA-Z]+((?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)\.?\b){4})' # noqa: E501
def main():
with open('diff.txt', 'r') as f:
data = [line.strip() for line in f.readlines()]
for line in data:
@iagoalonsomrf
iagoalonsomrf / replace_screenshot_keybinding.sh
Created November 30, 2022 17:05 — forked from ibLeDy/replace_screenshot_keybinding.sh
Set Flameshot as the default screenshot tool
# Release default `window-screenshot` keybinding (Ubuntu 19.10)
gsettings set org.gnome.settings-daemon.plugins.media-keys window-screenshot '[]'
# Replace default `screenshot` binding with the default from `window-screenshot`
gsettings set org.gnome.settings-daemon.plugins.media-keys screenshot '<Alt>Print'
# Create a new custom keybinding (taking for granted that this would be the first created)
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
# Give it a name
@iagoalonsomrf
iagoalonsomrf / docker-compose.yaml
Last active October 21, 2022 14:31
Best practices for writing docker-compose files
version: "3" # specify compose spec version
services:
db: # define a service name (docker-compose restart db)
image: postgres:13 # specify an image tag
container_name: db # define a container name (docker logs -f db)
restart: unless-stopped # specify an appropiate restart policy
volumes:
- psql_data:/var/lib/postgresql # use named volumes
healthcheck:
@iagoalonsomrf
iagoalonsomrf / .editorconfig
Last active October 10, 2022 17:33
Standardised editor configuration
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
[*.{json,py,tf}]
@iagoalonsomrf
iagoalonsomrf / Dockerfile
Last active September 8, 2023 14:20
Best practices for writing Dockerfiles
ARG DEBIAN_FRONTEND=noninteractive
# Tags should be as specific as possible
FROM ubuntu:jammy-20220815
# Set default locale in UTF-8 enabled mode
ENV LANG=C.UTF-8
# Add metadata to the image
LABEL maintainer="ops@marfeel.com"
@iagoalonsomrf
iagoalonsomrf / pyproject.toml
Created August 2, 2022 11:24 — forked from ibLeDy/pyproject.toml
Example configuration files for Python packages
[build-system]
requires = [
"setuptools",
"wheel",
]
build-backend = "setuptools.build_meta"
[tool.black]
line-length = 120
skip-string-normalization = true