Skip to content

Instantly share code, notes, and snippets.

View ericblue's full-sized avatar

Eric Blue ericblue

View GitHub Profile
@ericblue
ericblue / nextauth_logout_example.tsx
Last active April 27, 2025 13:34
NextAuth - Logout example - manually POSTing to /api/auth/signout instead of calling 'signOut()'
"use client";
import { useEffect } from 'react';
// Note: Logout works with a direct link to NextAuth's unbranded /api/auth/signout
// however signOut does not appear to work consistently (e.g. doesn't clear session) and may cause redirect loops
async function fetchCsrfToken() {
const response = await fetch('/api/auth/csrf');
const data = await response.json();
@ericblue
ericblue / set_heroku_env.sh
Created June 12, 2024 20:14
Bash script to bulk update environment variables for a given Heroku app
#!/bin/bash
# This script is used to set environment variables for a Heroku application.
# It reads variables from a provided .env file and sets them for the specified Heroku application.
# The script ignores HOST and PORT variables.
# Usage: ./set_heroku_env.sh path_to_env_file heroku_app_name
# Check if the .env file and app name are provided as arguments
if [ -z "$1" ] || [ -z "$2" ]; then
@ericblue
ericblue / gist:52b087ca713fc4e66a803c2a444d979b
Created May 17, 2024 23:27
generate_cpanfile.pl - Custom, but simple script to dynamically generate a cpanfile for any perl project
#!/usr/bin/env perl
use strict;
use warnings;
use Module::ExtractUse;
use Data::Dump;
use Pod::Usage;
my $p = Module::ExtractUse->new;
@ericblue
ericblue / gist:5474041e0dd0f5a12e5808fd941335f5
Created March 17, 2023 01:39
Generates configurations for Apache and Nginx in use with CloudFlare for capturing end-user's real IP address using the CF-Connecting-IP header
#!/bin/bash
# Generates configurations for Apache and Nginx in use with CloudFlare for capturing end-user's real IP address using the CF-Connecting-IP header
LATEST_CLOUDFLARE_IPV4_IPS='https://www.cloudflare.com/ips-v4';
LATEST_CLOUDFLARE_IPV6_IPS='https://www.cloudflare.com/ips-v6';
function usage() {
echo "Usage: $0 <apache|nginx>";
}
@ericblue
ericblue / gist:acb761461519ec0c9fae03222a604416
Created January 30, 2023 02:16
Gradle - Support loading of environment variables from a custom .env file prior to run (works in IDE and CLI)
// Loads environments variables from files contained in .env located in the CWD'
// See: https://stackoverflow.com/questions/36322536/how-to-set-an-environment-variable-from-a-gradle-build
run.doFirst {
if (project.file('.env').exists()) {
file('.env').readLines().each() {
if (!it.isEmpty() && !it.startsWith("#")) {
def (key, value) = it.tokenize('=')
if (System.getenv(key) == null) {
println "Setting environment variable for ${key}"
environment key, value
@ericblue
ericblue / edit_env.sh
Created May 13, 2020 19:52
Sync .envrc and .env files for use in CLI and IntelliJ
#!/bin/bash
# Supports using environment variables from direnv in both CLI and IntelliJ
# CLI uses direnv .envrc (https://direnv.net/)
# IntelliJ uses .env files using the following plugin https://plugins.jetbrains.com/plugin/7861-envfile
#
# The master env config file is the .env file. Any edits using this script will export to an updated .envrc file
# Edit source .env file
pico .env
# Generate a new Key
openssl genrsa -out cert-domain.key 2048
# Generate a new Certificate Request
openssl req -new -sha256 -key cert-domain.key -out cert-domain.csr
#!/bin/bash
# launch_screens.sh - https://gist.github.com/ericblue/5bad210e113c56ade8766506fc99e611
# Launch script using screens to automatically create named sessions and launch executed commands while detaching immediately
# Useful as a startup helper script to create multiple screen sessions you can later reattach to (e.g. screen -r screen1)
# Key name = the screen session name
# Key value = command to execute
declare -A screens=(
["screen1"]="/usr/bin/top"
@ericblue
ericblue / deploy_ssh_key.sh
Created September 19, 2016 23:29
Add new SSH trusted host key
#!/bin/sh
# Deploys new authorized key from id_rsa.pub via SSH so new SSH connections will not require password authentication
# Example: cd ~/user; ./deploy_ssh_key.sh [email protected]
if [ $# -lt 1 ]
then
echo "Usage: $0 <user@hostname>";
exit 1;
Verifying that +ericblue is my blockchain ID. https://onename.com/ericblue