Skip to content

Instantly share code, notes, and snippets.

View rtfpessoa's full-sized avatar

Rodrigo Fernandes rtfpessoa

View GitHub Profile
@rtfpessoa
rtfpessoa / minimal-bash-template.sh
Last active October 7, 2025 14:45
Minimal Bash Script Template
#!/usr/bin/env bash
# Source: https://betterdev.blog/minimal-safe-bash-script-template/
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
@rtfpessoa
rtfpessoa / tvi-player-downloader.sh
Last active September 17, 2024 16:57
TVI Player Downloader
#!/usr/bin/env bash
set -eux
for SEASON_NUMBER in 1 2; do
for EPISODE_NUMBER in 1 2; do
EPISODE_URL="http://tviplayer.iol.pt/programa/pesadelo-na-cozinha/58bd77b50cf26a3bdcfca690/episodio/t${SEASON_NUMBER}e${EPISODE_NUMBER}"
PLAYLISTS_BY_QUALITY_URLS=$(curl -L $EPISODE_URL 2>/dev/null | grep 'vod/_definst_' | awk -F, '{print $3}' | sed -E 's/"videoUrl":"(.*)"/\1/')
youtube-dl -f best --audio-quality 0 -o pesadelo-na-cozinha-S01E0${EPISODE_NUMBER}.ts --prefer-ffmpeg $PLAYLISTS_BY_QUALITY_URLS &
@rtfpessoa
rtfpessoa / cgd.py
Created March 16, 2016 22:18 — forked from brunomlopes/cgd.py
Simple api to fetch accounts, balances and transactions from Caixa Geral de Depósitos's ( CGD ) API used by their Windows 8 application.
# gist: https://gist.github.com/4397792
# Usage:
# session = cgd.CgdSession(uid, password)
# session.login()
# session.load_latest_transactions(account_key)
# 'session.known_accounts' is now populated with the initial accounts taken from the login response,
# and the data for the 'account_key' account.
# session.load_latest_transactions(account_key) loads the latest transactions and balances for a given account.
@rtfpessoa
rtfpessoa / 2f-two-factor-timer.js
Last active March 20, 2016 22:43
Two Factor Timer
var updateTimer = function(period, updateTokenCallback) {
// Get current time seconds
var epocSecs = Math.floor((+new Date()) / 1000);
var sec = epocSecs % period;
var secsToNext = 0;
// Fire if clock has struck 0 or 'period'
if (sec == 0 || sec == period) {
updateTokenCallback();
@rtfpessoa
rtfpessoa / postgresql-blockers-waiters.sql
Created February 18, 2016 23:11
Postgresql Blockers and Waiters
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS blocking_statement
FROM pg_catalog.pg_locks blocked_locks
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks
ON blocking_locks.locktype = blocked_locks.locktype
@rtfpessoa
rtfpessoa / LittleTree.scala
Created November 14, 2015 21:01
LittleTree Implementation
package com.rtfpessoa.scala
import scala.language.postfixOps
import scala.util.Properties
case class LittleTree(height: Int) {
implicit class IntOps(int: Int) {
def isOdd = int % 2 > 0
}
@rtfpessoa
rtfpessoa / script-directory.sh
Created April 27, 2015 18:05
Find current script directory (shell)
#!/bin/sh
#
# Find current script directory
#
ScriptDirectory="$( cd "$( dirname "$0" )" && pwd )"
echo "This script is currently @ $ScriptDirectory"
@rtfpessoa
rtfpessoa / main.c
Created April 2, 2015 14:28
Playing with C
#include <stdio.h>
int main(void)
{
int x = 1;
int y = 2;
int val = 5 + ( x = 3, x + y ) + 7;
printf("VAL: %d | X: %d | Y: %d", val, x, y);
@rtfpessoa
rtfpessoa / .tmux.conf
Last active August 29, 2015 13:59
Tmux Configuration
# cat << ►_◄ > /dev/null
#
# Tmux config
#
# set Zsh as your default Tmux shell
set-option -g default-shell /bin/zsh
# colors please