Skip to content

Instantly share code, notes, and snippets.

View tofran's full-sized avatar
🚲

Francisco Marques tofran

🚲
View GitHub Profile
@tofran
tofran / get-github-repo-oidc-sub.sh
Created August 2, 2026 11:43
Helper script to generate the correct GitHub Actions OIDC sub claim for use in AWS IAM trust policies (and other cloud providers). Required for repositories created after July 15, 2026, which use an immutable format including numeric owner/repo IDs.
#!/usr/bin/env bash
# GitHub Actions OIDC subject claim helper
#
# Repositories created after July 15, 2026 use an immutable subject (sub) claim
# format that includes numeric owner and repo IDs instead of just names:
#
# New: repo:owner@OWNER_ID/repo@REPO_ID:ref:refs/heads/main
# Old: repo:owner/repo:ref:refs/heads/main
#
# This prevents subject claim reuse if a GitHub username or repo name is recycled
@tofran
tofran / generate_sample_portuguese_nifs.py
Last active March 3, 2026 15:20
Lista de NIFs Portugueses fictícios mas válidos
"""
Gerador de NIFs portugueses de teste válidos.
Formato: [100..999] 000 00 X (onde X é o dígito de controlo)
"""
def calcular_digito_controlo(primeiros_8: str) -> int:
"""Calcula o dígito de controlo de um NIF com base nos primeiros 8 dígitos."""
pesos = [9, 8, 7, 6, 5, 4, 3, 2]
soma = sum(int(d) * p for d, p in zip(primeiros_8, pesos))
@tofran
tofran / smtp_email_test.py
Last active April 15, 2025 17:25
SMTP Email sending credentials test
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
smtp_server = input("smtp server")
smtp_port = 587 # Usually 587 for TLS, 465 for SSL
receiver_email = input("receiver email")
sender_email = input("sender email")
sender_name = input("sender name")
# Go thru all vercel projects in any of your organizatons and remove the development "target"
# from all secrets that have other targets
import requests
VERCEL_TOKEN = "YOUT_TOKEN"
HEADERS = {"Authorization": f"Bearer {VERCEL_TOKEN}"}
BASE_API_URL = "https://api.vercel.com"
@tofran
tofran / Download_bolt_invoices.py
Last active April 1, 2024 00:01
Bolt business invoice downloader
import csv
import requests
from datetime import datetime
def download_and_save_invoice(url, date_str):
response = requests.get(url)
response.raise_for_status()
file_name = f"ride_{date_str}.pdf"
@tofran
tofran / python-webbrowser-bypass.sh
Last active January 29, 2024 20:53
Simle utility to fake Python's `webbroser` and be able to bypass code that relies on it when there's no browser on the system.
#!/bin/sh
#
# Simle utility to fake Python's `webbroser` (https://docs.python.org/3/library/webbrowser.html).
# Usefull for when no GUI is available. For example inside a Docker container.
#
# Copy paste this code the terminal:
export BROWSER="~/fake-browser.sh:$BROWSER"
echo 'echo "Fake browser called with: $@" && touch ~/fake-browser.log && echo "$@" >> ~/fake-browser.log' > ~/fake-browser.sh
COMMUNICATION_SERVICES_CONNECTION_STRING=
EMAIL_SENDER=
@tofran
tofran / nbt-copy.py
Created December 26, 2020 00:34
Copy minecraft NBT properties from one file into another
#!/usr/bin/env python3
# Copy minecraft NBT properties from one file into another
# Usage:
# ./nbt-copy.py <source_file> <destination_file> <property> [properties]
#
# Requires nbt:
# pip install nbt
import argparse
@tofran
tofran / iLoConsoleShortcut.js
Created April 19, 2020 18:55
Userscript to add a shortcut to the HTML5 console in HP's iLo UI
// ==UserScript==
// @name HP iLo 4 console shortcut
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds a quick link to the HTML5 console in HP's iLo UI. Make sure you match the script to your server(s) IPs
// @author tofran
// @match https://<YPUR_SERVER_IP_HERE>/html/masthead.html
// @grant none
// ==/UserScript==
const findCacheDir = require('find-cache-dir');
const Cache = require("file-system-cache").default;
const cache = Cache({
basePath: findCacheDir({ name: 'storybook' }),
ns: 'storybook'
});
const cache_data = {
success: true,