Skip to content

Instantly share code, notes, and snippets.

View vjvelascorios's full-sized avatar
🎯

vjvelascorios vjvelascorios

🎯
View GitHub Profile
@vjvelascorios
vjvelascorios / .organizer.bash
Last active May 26, 2023 20:44
File organizer bash
#!/bin/bash
#Notes:
#1. You can run this script in two ways:
# a). Saving this script in the folder that you need to organize and bash, like: "bash .organizer.bash"
# b) Saving this file where you want, open the terminal in the directory you need to organize, but specifying where the program is, like: "bash "home/xyz/Downloads/organizer.bash"
# Proved in Ubuntu 22.04 and Loc-Os 22.
# Directory keys
IMAGES_DIR="images"
@vjvelascorios
vjvelascorios / yml_creator.sh
Created July 2, 2023 05:57
Utility for labnote that allows create automatically the "config.yml" file, just bash this file inside the folder with all content (folders) and get categories according to folder names
#!/bin/bash
###########################################################
###########################################################
# Notes:
# 1. once the file is generated, move the file upper (as in the original example), change the `input_dir` link (just writting the folder name, as in the original example)
# and reorder categories if you want.
# 2. if you want to include images in the `.yml`, be careful with indentation in `image: "images/dogo.jpeg"` (must be the same indentation as `patterns`).
# 3. non-english speakers must be careful with directory names and files, if you have problems in the `index` creation, fix accents and tricky characters.
# for more information look on https://github.com/khughitt/labnote
@vjvelascorios
vjvelascorios / folder_creator.sh
Created July 2, 2023 07:22
Folder creation for any file inside some target folder and move into it.
#!/bin/bash
# Obtener la lista de archivos en el directorio actual (excepto el script .sh)
archivos=$(find . -maxdepth 1 -type f ! -name "$0")
# Guardar el separador de línea en una variable temporal para evitar cambios globales
IFS=$'\n'
# Recorrer cada archivo
for archivo in $archivos; do
@vjvelascorios
vjvelascorios / CRAN_manuals_downloader.R
Created August 16, 2023 07:21
Download all packages manuals loaded in a R session
#===========================================
rm(list=ls())
# Load packages
pacman::p_load(tidyverse, qs, data.table, scales, lubridate, WDI, strucchange, dplyr)
# Get packages loaded in the environment
load_packages <- search()[grepl("^package:", search())]
package_names <- sub("^package:", "", load_packages)
# Filter CRAN package names
CRAN_packages_names <- package_names[grepl("^[a-zA-Z]", package_names)]
@vjvelascorios
vjvelascorios / dfinanciero.sh
Created August 23, 2023 19:45
download automatically some pdf file
#!/bin/bash
# Get date (YYYY-MM-DD)
fecha=$(date +%Y-%m-%d)
# URL
url="https://www.elfinanciero.com.mx/graficos/edicion-impresa/download.php?file=edicion-digital.pdf"
# Download folder
carpeta_descargas="/home/vjvelascorios/Descargas/El Financiero"
#!/bin/bash
for input_file in input/*.{mp4,mkv,webm}; do
if [ -f "$input_file" ]; then
filename=$(basename "$input_file")
filename_noext="${filename%.*}"
output_file="output/$filename_noext.mp3"
# Convertir video a audio MP3 manteniendo los metadatos
ffmpeg -i "$input_file" -vn -c:a libmp3lame -q:a 4 -metadata title="$filename_noext" "$output_file"
@vjvelascorios
vjvelascorios / clean folder
Last active October 14, 2023 03:42
clean latex auxiliary files inside folders
#!/bin/bash
script_path=$(realpath "${BASH_SOURCE[0]}")
cd "$(dirname "$script_path")"
shopt -s extglob
find . -maxdepth 1 -type f ! -name "*.pdf" ! -name "*.md" ! -name "*.tex" ! -name "$(basename "$script_path" | tr -d '[:space:]')" -exec rm {} +
niveles <- function(x) {
resultado <- levels(as.factor(x))
return(resultado)
}
if (interactive() && requireNamespace("rsthemes", quietly = TRUE)) {
# Set preferred themes if not handled elsewhere..
rsthemes::set_theme_light("base16 Summerfruit Light {rsthemes}") # light theme
rsthemes::set_theme_dark("base16 Brewer {rsthemes}") # "base16 Brewer {rsthemes}" "base16 PhD {rsthemes}"
#!/bin/bash
# Verificar directorio
if ! ls *.pdf 1> /dev/null 2>&1; then
echo "Error: No se encontraron archivos en el directorio actual"
exit 1
fi
# Nombre del directorio actual
folder_name=$(basename "$PWD")
@vjvelascorios
vjvelascorios / alias_renamevideos.sh
Created November 13, 2023 07:40
include resolution in videos filename
alias renombrarvideos='find . -maxdepth 1 -type f \( -name "*.mp4" -o -name "*.mkv" -o -name "*.webm" \) -exec bash -c '\''
for file; do
resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$file" 2>/dev/null)
ext="${file##*.}"
if [ -n "$resolution" ] && ! [[ "$file" =~ "_$resolution" ]]; then
newname="$(basename "$file" ".$ext")_$resolution.$ext"
mv "$file" "$newname"
fi
done
'\'' bash {} +'