Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kriansa's full-sized avatar

Daniel Pereira kriansa

View GitHub Profile
@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 / 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 / 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 / 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
# 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-ssh-updater.sh
Created February 8, 2022 03:41
Update your Vultr firewall rules for your ingress SSH
#!/usr/bin/env bash
#
# Automatically updates the IP addresses for the ingress rules for SSH access on Vultr
#
# Requires: jq, curl, dig
main() {
export VULTR_API_KEY="YOUR-VULTR-API-KEY"
# Get existing rules at the Vultr firewall
@kriansa
kriansa / dedup.sh
Created August 9, 2020 14:39
Make hardlinks out of a list of duplicate files generated by rdfind
#!/usr/bin/env bash
help() {
echo "Makes hardlinks out of a list of duplicates files generated by rdfind."
echo
echo "usage: $0 <duplicates_file>"
}
main() {
local duplicates_file=$1
@kriansa
kriansa / evdev
Created April 15, 2019 03:00
XKB keyboard multimedia function keys
# Append this content to the file /usr/share/X11/xkb/rules/evdev
#
# Custom options patch by Kriansa
! option = symbols
custom:multimedia_fn_keys = +media(multimedia_fn_keys)
custom:scroll_lock_key_usable = +media(scroll_lock_key_usable)

Keybase proof

I hereby claim:

  • I am kriansa on github.
  • I am kriansa (https://keybase.io/kriansa) on keybase.
  • I have a public key whose fingerprint is BC27 7BE0 9E8A 6F10 59C3 911B 3E78 8475 6312 F945

To claim this, I am signing this object:

@kriansa
kriansa / openssl_tls_1.2.patch
Last active April 14, 2020 12:26
Source patch to add support to TLS 1.1 and 1.2 to Ruby 1.9.3 - https://garajau.com.br/2015/07/tls-1-1-and-1-2-support-for-ruby-1-9-3
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -107,6 +107,18 @@
OSSL_SSL_METHOD_ENTRY(TLSv1),
OSSL_SSL_METHOD_ENTRY(TLSv1_server),
OSSL_SSL_METHOD_ENTRY(TLSv1_client),
+#if defined(HAVE_TLSV1_2_METHOD) && defined(HAVE_TLSV1_2_SERVER_METHOD) && \
+ defined(HAVE_TLSV1_2_CLIENT_METHOD)
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2),
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2_server),