Skip to content

Instantly share code, notes, and snippets.

@zerolagtime
zerolagtime / k3b_to_playlist.py
Created August 28, 2015 04:04
Convert K3B audio projects into M4A files suitable for use on Apple devices that cannot handle numerous audio file formats.
#!/usr/bin/env python3
# Copyright 2015 by Charlie Todd except where noted below.
# You are granted permission to adapt this gist for your own project,
# but not to claim the work as entirely your own. Attribution must
# be provided in any derivative works in such a fashion that the
# final user of the software can see and understand the attribution.
import sys
import zipfile
import xml
import xml.dom.minidom
@zerolagtime
zerolagtime / internal_envsubst.sh
Created June 1, 2020 20:01
envsubst in pure bash/sed
#!/bin/bash
# this is a poor man's substitute for the envsubst command
function internal_envsubst() {
tfile=$(mktemp)
# use sed to build a sed input file specific to the current environment variables
env | sed -E -e '
# delete any special cases that make a mess of things
/^_=/d;
# deal with variables that have backslashes in them: \\tsclient\home
@zerolagtime
zerolagtime / script-template.sh
Last active March 19, 2021 13:52
BASH Shell Script Skeleton Template
#!/bin/bash
# This is a template script that has built-in logging
# with colored messages. It also supports command line parsing.
usage() {
echo "$0 [-h | --help] [-v | --verbose]"
echo " [-q | --quiet] [-w str | --with-parameter=str]"
echo " [--noisy]"
echo "Here is the reason this script exists."
echo "Where:"
@zerolagtime
zerolagtime / output-noisy-failure.txt
Created September 23, 2021 01:35
Bash skeleton - supports colored output for WARN and ERROR
$ ./script-template.sh --noisy
[[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] command -v /tmp/script-template.sh
[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] dirname /tmp/script-template.sh
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] cd /tmp
[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:201] pwd
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:201] here=/tmp
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:202] log_debug 'Starting main function of /tmp/script-template.sh'
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:159] main(): :
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:203] main
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:24] main(): log_info 'our informational message'
#!/bin/bash
# Usage:
# 0 * * * * /home/zerolagtime/bin/do_backup.sh -t hourly -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -k Documents # JOB_ID_1
# 0 0 * * * /home/zerolagtime/bin/do_backup.sh -t daily -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -k Documents # JOB_ID_2
# 0 0 * * 1 /home/zerolagtime/bin/do_backup.sh -t monthly -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -K Documents # JOB_ID_3
VERSION="2.2"
DEBUG=0
LOGFILE=""
KEYWORD=""
@zerolagtime
zerolagtime / test_tcp_socket.py
Created May 15, 2024 01:24
Test a TCP socket connection in Python
import socket
import sys
"""
Usage: python3 test_tcp_socket.py [host [port]]
Where host can be a string or IPv4 address. Port defaults to 80.
"""
host = sys.argv[1] if len(sys.argv)>1 and sys.argv[1] \
else "example.com"
port = int(sys.argv[2]) if len(sys.argv)>2 and sys.argv[2] else 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@zerolagtime
zerolagtime / example-bad-root.txt
Created May 15, 2024 01:40
Python to analyze a servers X.509 certificate chain - requires packages and libopenssl.do
Fetching certificate chain for: untrusted-root.badssl.com
0: Subject: <Name(C=US,ST=California,L=San Francisco,O=BadSSL,CN=*.badssl.com)>
0: Issuer: <Name(C=US,ST=California,L=San Francisco,O=BadSSL,CN=BadSSL Untrusted Root Certificate Authority)>
0: Serial Number: 16983658469221716870
0: Validity: From 2024-02-21 21:28:32+00:00 to 2026-02-20 21:28:32+00:00
{idx}: Extensions:
0.0: basicConstraints: <BasicConstraints(ca=False, path_length=None)>
0.1: subjectAltName: <SubjectAlternativeName(<GeneralNames([<DNSName(value='*.badssl.com')>, <DNSName(value='badssl.com')>])>)>
1: Subject: <Name(C=US,ST=California,L=San Francisco,O=BadSSL,CN=BadSSL Untrusted Root Certificate Authority)>