Skip to content

Instantly share code, notes, and snippets.

View rubenhortas's full-sized avatar
:octocat:

Rubén Hortas rubenhortas

:octocat:
View GitHub Profile
@rubenhortas
rubenhortas / b64urlencode_aliases
Last active May 18, 2024 21:20
Aliases to encode/decode strings in base64 url (and filesystem safe alphabet) using python3
alias b64urlencode='python3 -c "import sys, base64; print(base64.urlsafe_b64encode(bytes(sys.argv[1], \"UTF-8\")).decode(\"UTF-8\"))"'
alias b64urldecode='python3 -c "import sys, base64; print(base64.urlsafe_b64decode(bytes(sys.argv[1], \"UTF-8\")).decode(\"UTF-8\"))"'
@rubenhortas
rubenhortas / urlencode_aliases
Last active May 18, 2024 21:16
Aliases to encode/decode strings to/from URL encoding using python3
alias urldecode='python3 -c "import sys, urllib.parse as parse; print(parse.unquote_plus(sys.argv[1]))"'
alias urlencode='python3 -c "import sys, urllib.parse as parse; print(parse.quote_plus(sys.argv[1]))"'
@rubenhortas
rubenhortas / base64url
Last active March 19, 2024 20:56
Bash script to encode and decode to base64url
#!/usr/bin/env bash
# Encodes/decodes a string to/from base64url.
print_help() {
echo "Usage: $(basename "$0") [-d] STRING"
echo
echo "Without -d encodes the string to base64url."
echo
echo " -d decodes the string from base64url (or base64)"
@rubenhortas
rubenhortas / brightnessControl
Created March 9, 2024 17:56
Adjust the screen brightness modifying directly the gnome settings daemon power
#!/bin/bash
# Adjust the screen brightness modifying directly the gnome settings daemon power.
# To use this script you just have to save it in a path with execution permissions and assign the commands "brightnessControl up" and "brightnessControl down" to the keys using shortcuts.
# There's a better way to do this: install xdotool and assign the commands “xdotool key XF86MonBrightnessUp” and “xdotool key XF86MonBrightnessDown” to the brightness keys.
# With this solution the brightness indicator will come out on screen when we change the brightness.
# Arguments
way="$1" # Up or Down
@rubenhortas
rubenhortas / progress_bar_tqdm.py
Created March 9, 2024 17:29
Implement a progress bar in python using using tqdm
#!/usr/bin/env python3
"""
Implement a progress bar using using tqdm.
"""
from tqdm import tqdm
from time import sleep
if __name__ == '__main__':
@rubenhortas
rubenhortas / process_hunter.py
Last active March 19, 2024 20:47
Python script that looks for programs consuming CPU above a certain threshold and logs the results
#!/usr/bin/env python3
"""
Script that looks for programs consuming CPU above a certain threshold and logs the results.
"""
from types import FrameType
from psutil import cpu_percent, process_iter, NoSuchProcess, AccessDenied, ZombieProcess
from signal import signal, SIGINT
from datetime import datetime
@rubenhortas
rubenhortas / cpu_burner.py
Last active March 9, 2024 17:25
Python program to put the CPU at 100% usage
"""
A good example of a Python program that can put the CPU at 100% usage involves creating a CPU-intensive task
and then distributing this task across all CPU cores using the multiprocessing module.
"""
import math
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
@rubenhortas
rubenhortas / mathPuzzleForThirdGraders.c
Last active May 5, 2024 18:12
math puzzle for third graders solver
/*
Code to find all the permutations that solve the math puzzle for third graders from the image.
You're supposed to fill the blanks with the numbers 1 through 9 using each digit once.
Usage:
- Compile: gcc -O3 mathPyzzleForThirdGraders.c -o mathPyzzleForThirdGraders.out
- Run: ./mathPyzzleForThirdGraders.out
*/