Skip to content

Instantly share code, notes, and snippets.

View tcarreira's full-sized avatar

Tiago Carreira tcarreira

View GitHub Profile
@tcarreira
tcarreira / rename_videos.sh
Created August 15, 2023 12:56
rename every video file with timestamp from metadata
# oneliner:
ls videos | xargs -I{} sh -c 'cp "videos/{}" $(exiftool -createdate -S "videos/{}" | cut -d " " -f2- | sed "s/[: ]//g")_$(printf "%05d.mp4" $RANDOM)'
# ### script mode:
# for video in $(ls videos/); do
# createdate=$(exiftool -createdate -S "videos/${video}" | cut -d " " -f2- | sed "s/[: ]//g")
# fname=$(printf "%s_%05d.mp4" ${createdate} ${RANDOM})
# cp "videos/$video" "$fname"
@tcarreira
tcarreira / Go-Makefile
Created April 11, 2023 21:12 — forked from thomaspoignant/Makefile
My ultimate Makefile for Golang Projects
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=example
VERSION?=0.0.0
SERVICE_PORT?=3000
DOCKER_REGISTRY?= #if set it should finished by /
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true
GREEN := $(shell tput -Txterm setaf 2)
@tcarreira
tcarreira / euribor-6m-month-rate.go
Last active July 18, 2024 18:54
Get the euribor 6m rate for a given month (average of all days on a given month) - Go or Python
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)
@tcarreira
tcarreira / .bashrc
Created August 25, 2022 20:26
kubectl get filter by annotation
# including this inside .bashrc and use the kfilter command on your shell
function escape_things() {
echo $1 | sed -E "s@([\.\/])@\\\\\1@g"
}
function kfilter() {
# kfilter -n <namespace> <annotation> <value> # search on a single namespace
# kfilter <annotation> <value> # all namespaces (takes longer)
if [ "_$1" = "_-n" ] ; then
@tcarreira
tcarreira / dojo.js
Created March 30, 2022 19:47
Solving AdventOfCode2015 - day 06 - for Dojo
function part1(matrix, instructions) {
let newMatrix = matrix.map(row => row.slice());
instructions.forEach(instructionString => {
instruction = parseLine(instructionString);
newMatrix = changeLights(newMatrix, instruction.operation, instruction.range);
})
return newMatrix.reduce((acc, row) => acc + row.reduce((acc, cell) => acc + cell, 0), 0);
@tcarreira
tcarreira / terraform-skip-prevent-destroy.sh
Created February 22, 2022 14:19
Terraform wrapper for temporarily disable 'prevent_destroy = true'
#!/bin/sh
BASE_DIR=$(dirname "$0")
_cleanup() {
find "${BASE_DIR}" -type f -name "*.tf" -exec sh -c 'sed -i "s@prevent_destroy = false #REPLACED@prevent_destroy = true@g" $1' shell {} \;
}
_replace_prevent_destroy() {
find "${BASE_DIR}" -type f -name "*.tf" -exec sh -c 'sed -i "s@prevent_destroy = true@prevent_destroy = false #REPLACED@g" $1' shell {} \;
}
@tcarreira
tcarreira / set_repo_user.sh
Created March 10, 2021 13:16
Config git USER+EMAIL for every repository inside a directory
#!/bin/sh
GIT_USER="${GIT_USER:-My Name}"
GIT_EMAIL="${GIT_EMAIL:-mymail@users.noreply.github.com}"
INFO=${INFO:-yes}
DIR="${1:-.}"
apply_git_config() {
target=$1
@tcarreira
tcarreira / run-my-docker-compose-service.sh
Last active February 12, 2021 22:52
Run my docker-compose as a systemd service.
#!/bin/sh
DOCKER_COMPOSE_PATH="/data/docker"
SERVICE_NAME="my-docker-compose.service"
SCRIPT_NAME="$(realpath "$0")"
echo_service_content() {
cat >&1 <<EOF
[Unit]
Description=Docker Compose service
@tcarreira
tcarreira / get_mediawiki_journal_year.py
Last active February 6, 2021 20:12
This script prints a mediawiki style Journaling page for the current year.
#!/usr/bin/env python3
# run with: python3 get_mediawiki_journal_year.py
# or send to the clipboard using: python3 get_mediawiki_journal_year.py | xclip -selection clipboard
# source: https://gist.github.com/tcarreira/dc75ab8e560a1134fbdd1fd280405e78
"""
This script prints a mediawiki style Journaling page.
"""
@tcarreira
tcarreira / gen_random_jwt_token_rs256.py
Created December 4, 2020 14:22
Generate a JWT token signed by a random self-signed key (RS256)
#!/usr/bin/env python3
import subprocess
from datetime import datetime, timedelta
import jwt
subprocess.call(
"openssl genrsa -out private.pem 1024".split(" "), stderr=subprocess.DEVNULL
)