Skip to content

Instantly share code, notes, and snippets.

View tcarreira's full-sized avatar

Tiago Carreira tcarreira

View GitHub Profile
@tcarreira
tcarreira / 0_reuse_code.js
Created July 10, 2017 16:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Enable SSH
touch /tmp/1/ssh
# Configure WiFi
cat > /tmp/1/wpa_supplicant.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<TWO_LETTER_ISO_COUNTRY_CODE>
network={
@tcarreira
tcarreira / convert_encoding.sh
Last active June 28, 2020 18:31
Convert windows encoding (ISO-8859-15) to utf8 (with backups)
OLDIFS=$IFS
IFS=$'\n'
prefix=".old.conv.$(date +%Y%m%d_%H%M%S)"
for file in $(find . -type f -name '*.php*') ; do
if file "$file" | grep "ISO-8859 text" 2>/dev/null; then
echo "convert;${file};$(file $file)"
dir=$(dirname "$file")
@tcarreira
tcarreira / bookmark
Last active July 16, 2020 17:16
Save a POST request as a bookmark
javascript:post('<site_url>',{param1:'value1',param2:'value2'});function post(a,b){const c=(e,f)=>Object.assign(document.createElement(e),f),d=c('form',{action:a,method:'post',hidden:true});for(const[e,f]of Object.entries(b))d.appendChild(c('input',{name:e,value:f}));document.body.appendChild(d),d.submit()}
@tcarreira
tcarreira / 8D_to_top4_tracks.txt
Created August 19, 2020 13:10
Audacity macro for 8D - 4 tracks
SelectTracks:Mode="Set" Track="0" TrackCount="1"
SelTrackStartToEnd:
Duplicate:
SelectTracks:Mode="Set" Track="0" TrackCount="1"
SelTrackStartToEnd:
Duplicate:
SelectTracks:Mode="Set" Track="1" TrackCount="1"
SelTrackStartToEnd:
Duplicate:
SelectTracks:Mode="Set" Track="1" TrackCount="1"
@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
)
@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 / 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 / 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 / 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 {} \;
}