Skip to content

Instantly share code, notes, and snippets.

BEGIN MESSAGE.
K9m3gUTNgkxnZIC iVo9NtpWywzNZlV TXqqNafJTX9l1o9 i45egdvWYeqn36F
1F5G5Un1czApQdv rWioRcZNTjmTCKq 6Xr2MZHgg4ZFWB0 qUfubS9YbvB6W1n
6CCBuup1FSYrxJl KmtRlytSFGgkA2w QptFNxMrqCTA2Q0 e0oimf2RbQYNYp6
KkdradiwhAtkRzu 2yjdhHQJBj5WIF7 a4YBt0aLMzWSiL.
END MESSAGE.
#!/usr/bin/env python3
import argparse
import smtplib
import ssl
import dns.resolver # Required for DNS lookup
from email.mime.text import MIMEText
def get_mx_record(domain):
"""
@DamnedFacts
DamnedFacts / do_nothing_script.py
Last active January 9, 2020 16:30
The "do nothing script", an idea of writing scripts that document the actions. This leads to self-documentation for manual processes, leading into automating each step later.
import sys
def wait_for_enter():
input("Press Enter to continue: ")
class CreateSSHKeypairStep(object):
def run(self, context):
print("Run:")
print(" ssh-keygen -t rsa -f ~/{0}".format(context["username"]))
wait_for_enter()
@DamnedFacts
DamnedFacts / ssh_config
Last active November 30, 2020 15:26
Cool way to use Bash in an SSH proxy if nc (netcat) is not on the remote system, or if the remote host does not support ProxyJump. Use in your ~/.ssh/config file.
Host *
# Cool one-liner. Use bash to connect to ssh host on port 22 and use shell to read/write data!
# https://www.commandlinefu.com/commands/view/14406/read-and-write-to-tcp-or-udp-sockets-with-common-bash-tools
ProxyCommand ssh -q joesmith@remotehost 'host=%h;exec 7<>/dev/tcp/${host}/22; cat <&7 & cat >&7; exec 7>&-'
@DamnedFacts
DamnedFacts / archive_data.sh
Last active May 28, 2019 18:01
An exercise in embarassing parallelization of Bash functions, done through a file archival example
#!/bin/sh
PREFILLED=false
SLOTS=8
END_YEAR=2099
year=2018
declare -a procs[8]
@DamnedFacts
DamnedFacts / mount_vdi.sh
Created May 15, 2019 16:38
Mount a VirtualBox Virtual Disk Image (VDI) on a Mac using hdiutil
#!/bin/sh
TEMP="$1.$$.img"
trap "rm -f $TEMP 2>/dev/null" 1 2 3 11 15
offset=`hexdump -s 0x158 -n 4 "$1" | head -1 | awk '{print $5 $4 $3 $2}'`
offset512=`echo "obase=16; ibase=16; $offset / 200" | bc`
ln "$1" "$TEMP"
hdiutil attach "$TEMP" -nomount -section "0x$offset512"
rm -f "$TEMP"
@DamnedFacts
DamnedFacts / tm_repair.sh
Last active September 5, 2019 03:50
A quick script to repair Time Machine sparsebundles. This should be a fix to the dreaded "To improve reliability, Time Machine must create a new backup for you" error.
#!/bin/bash
# From: https://jd-powered.net/notes/fixing-your-time-machine-backup/
ext=${1##*.}
if [[ "${ext}" != "sparsebundle" ]] || [[ -z ${1} ]]; then
echo "A sparsebundle disk image is required."
exit 1
fi
@DamnedFacts
DamnedFacts / prompt.sh
Created April 3, 2019 03:26
Custom Bash prompt, with colors
# Colors
declare -A colors
colors[NC]="\033[0m"
colors[NORMAL]="\033[00m"
#colors[BLINK]="\033[05m"
#colors[DEFAULT]="\033[39m"
#colors[BLACK_BG]="\033[40m"
colors[BLACK]="\033[0;30m"
colors[BOLD_BLACK]="\033[1;30m"
colors[RED]="\033[0;31m"
#!/usr/bin/env python3
import datetime
from io import BytesIO
from sys import argv
import requests
from PyPDF2 import PdfFileReader
from icalendar import Calendar, Event, Alarm
from icalendar.prop import vRecur
from pytz import UTC
#! /usr/local/bin/python
SMTPserver = 'smtp.att.yahoo.com'
sender = 'me@my_email_domain.net'
destination = ['recipient@her_email_domain.com']
USERNAME = "USER_NAME_FOR_INTERNET_SERVICE_PROVIDER"
PASSWORD = "PASSWORD_INTERNET_SERVICE_PROVIDER"