Skip to content

Instantly share code, notes, and snippets.

@charlesrc019
charlesrc019 / server_shutdown_ssh_timeout.sh
Last active October 22, 2026 20:01
server_shutdown_ssh_timeout.sh
#!/usr/bin/env bash
#
# SSH AUTO-SHUTDOWN - Ubuntu 24.04 LTS
#
# SETUP:
# 1. sudo nano /usr/local/sbin/autodown_ssh
# 2. Paste this script, save, and exit.
# 3. sudo chmod +x /usr/local/sbin/autodown_ssh
# 4. Test: sudo /usr/local/sbin/autodown_ssh
import boto3
import email
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from botocore.exceptions import ClientError
import logging
from email.utils import parseaddr, formataddr
import hashlib
# Configure logging.
@charlesrc019
charlesrc019 / server_sync_route53_via_api.ps1
Last active October 22, 2026 19:26
server_sync_route53_via_api.ps1
# Setup. If on an AWS instance, add to /var/lib/cloud/scripts/per-boot/update-route53.sh as root owner and runnable.
# Fetch the public IPv4 address from the metadata service.
$ipUrl = "http://checkip.amazonaws.com/"
$publicIp = Invoke-RestMethod -Uri $ipUrl
if (-not $publicIp) {
Write-Error "Failed to retrieve the public IP address."
exit 1
}
Write-Output "Public IP Address: $publicIp"
@charlesrc019
charlesrc019 / web_manage_aws_services_easy.py
Created November 13, 2024 22:34
web_manage_aws_services_easy.py
import json
import boto3
def lambda_handler(event, context):
msg = None
try:
data = json.loads(event['body'].lower())
@charlesrc019
charlesrc019 / math_convert_datestamp_to_epoch.py
Created November 11, 2024 15:30
math_convert_datestamp_to_epoch.py
import time
import calendar
def dattim_to_epoch(dattim, fmt='%Y%m%d%H%M'):
return int(calendar.timegm(time.strptime(str(dattim), fmt)))
@charlesrc019
charlesrc019 / math_convert_epoch_to_datestamp.py
Created November 11, 2024 15:29
math_convert_epoch_to_datestamp.py
import datetime
def epoch_to_dattim(epoch_time, fmt='%Y%m%d%H%M%S'):
return int(datetime.datetime.utcfromtimestamp(int(epoch_time)).strftime(fmt))
@charlesrc019
charlesrc019 / endpoint_rename_to_numbers.sh
Created November 8, 2024 02:26
endpoint_rename_to_numbers.sh
#!/bin/zsh
# Check if directory argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/directory"
exit 1
fi
# Set the directory
directory="$1"
@charlesrc019
charlesrc019 / web_store_variables.php
Created November 8, 2024 02:25
web_store_variables.php
<?php
// Initialize global parameters.
$SQL_USERNAME = "";
$SQL_PASSWORD = "";
$SQL_DATABASE = "";
$conn = NULL;
// Function. Display an JSON message.
function jsonMessage ($msg='Generic error.', $success=FALSE) {
@charlesrc019
charlesrc019 / web_track_device_ips.php
Created November 8, 2024 02:24
web_track_device_ips.php
<?php
$SQL_DATABASE = "";
$SQL_USERNAME = "";
$SQL_PASSWORD = "";
// Function. Display an JSON message.
function jsonMessage ($MessageDetails='Generic error.', $IsSuccess=FALSE) {
// Return message.
@charlesrc019
charlesrc019 / web_automate_byu_ytime.php
Last active November 8, 2024 02:23
web_automate_byu_ytime.php
<?php
/*
/ BYU Y-TIME TRIGGER FOR IFTTT (UNOFFICIAL)
/ Author: Charles Christensen
/ Edited: April 3, 2019
/
/ Required Dependencies:
/ - IFTTT
/ - PHP Webserver