Skip to content

Instantly share code, notes, and snippets.

View kriansa's full-sized avatar

Daniel Pereira kriansa

View GitHub Profile
# This will generate a monospaced progress bar with a progress percentage displayed in the center of it
# Usage: progress-bar <percentage> <width>
# Example output: "———————— 80% —————— "
progress-bar() {
local percentage=$1
local width=$2
local fill_bars; fill_bars=$(( width * percentage / 100 ))
local fill_spaces; fill_spaces=$(( width - fill_bars ))
local bar=""
@kriansa
kriansa / vultr-firewall-updater.sh
Created October 22, 2022 21:54
Update your Vultr firewall rules to only accept your IP address as incoming SSH
#!/usr/bin/env bash
#
# Automatically updates the IP addresses for the ingress rules for SSH access
# at my home proxy instance on Vultr
#
# Requires: jq, curl, dig
config() {
# Define your Vultr API Key
export VULTR_API_KEY=YOUR-VULTR-API-KEY
@kriansa
kriansa / on-page-load.js
Created April 29, 2023 20:28
Authenticate with ID Token on Nuxt.js
// Here after the $auth is properly initialized, we add the idToken as part of the Authorization
// header sent to our API, as it is authenticatable by using the IDToken (JWT), not the AuthToken.
$axios.interceptors.request.use((config) => {
config.headers['Authorization'] = `Bearer ${$auth.strategy.idToken.get()}`
return config
})
// By default, axios request interceptors are executed in the order they are added in the
// interceptors stack. At this point on runtime, Nuxt Auth has already injected an interceptor
// that adds an Authorization token to the requests, so we are unable to override it unless we
@kriansa
kriansa / plugins-axios.js
Created May 8, 2023 03:13
Enable CSRF on Nuxt/Axios for Rails APIs
export default function ({ $axios }) {
// Because API is always considered as a cross-domain call, the default
// XSRF feature available on axios will not work for us, because they use
// cookies and cookies aren't readable in cross-domains. Instead we must
// rely on having CSRF sent on every header request by the backend, and
// then we store that value to send on the next subsequent request.
//
// See: https://github.com/axios/axios#interceptors
$axios.interceptors.request.use((config) => {
if (!config.method.includes('get', 'head', 'options')) {
@kriansa
kriansa / dotenv.sh
Last active February 21, 2024 04:02
Pure bash dotenv
# This is useful for loading a .env file and ensuring you don't override the
# environment variables already set.
#
# Usage: load-env-file filename.env
load-env-file() {
local env_file=$1
# Save a reference of all existing variables
while IFS= read -rd $'\0' var; do
name="${var%%=*}"
@kriansa
kriansa / log.go
Created June 16, 2025 13:06
Simple slog wrapper with good DevX
package log
import (
"context"
"log/slog"
"os"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"