Skip to content

Instantly share code, notes, and snippets.

View pythoninthegrass's full-sized avatar

pythoninthegrass

View GitHub Profile
@pythoninthegrass
pythoninthegrass / hello-ansible.yml
Created August 29, 2024 21:16
Kestra mvp for inline ansible inventory and playbook. Alternative is namespace files or the git plugin
id: ansible
namespace: company.team
tasks:
- id: ansible_task
type: io.kestra.plugin.ansible.cli.AnsibleCLI
inputFiles:
inventory.ini: |
localhost ansible_connection=local
myplaybook.yml: |
@pythoninthegrass
pythoninthegrass / ticktick_to_obsidian.py
Created August 23, 2024 19:11
Generate markdown files from TickTick backup CSV for use with Obsidian + Python Scripter plugin
#!/usr/bin/env python
import sys
import csv
import re
from pathlib import Path
python_script = Path(sys.argv[0])
vault_path = Path(sys.argv[1] if len(sys.argv) > 1 else "../../..").resolve()
file_path = Path(sys.argv[2] if len(sys.argv) > 2 else ".").resolve()
services:
cosmos-server:
image: azukaar/cosmos-server:latest
container_name: cosmos-server
hostname: cosmos-server
restart: on-failure:3
# ports:
# - 80:80
# - 443:443
# - 4242:4242/udp
@pythoninthegrass
pythoninthegrass / backup.sh
Last active August 9, 2024 21:57
rsync backup script with logging and crontab usage
#!/usr/bin/env bash
set -euo pipefail
# trap exit signals 2, 1, 15
trap "exit" SIGINT SIGHUP SIGTERM
cat << 'DESCRIPTION' >/dev/null
USAGE:
backup.sh [SRC] [DEST] [EXT] [TLD] [SUB_DIR] [LOG_PATH]
@pythoninthegrass
pythoninthegrass / bootstrap_acme
Last active October 24, 2024 20:31
acme.sh wrapper for godaddy (migrated from certbot)
#!/usr/bin/env bash
# shellcheck disable=SC2120
# exit on signals: 2, 1, 15
trap 'exit' SIGINT SIGHUP SIGTERM
# $USER
[[ -n $(logname >/dev/null 2>&1) ]] && logged_in_user=$(logname) || logged_in_user=$(whoami)
@pythoninthegrass
pythoninthegrass / devbox
Last active July 12, 2024 17:11
Shim for devbox to automatically append --env-file to services argument
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2317
# shift shim behind real binary
export PATH="/usr/local/bin/:${PATH}"
# env vars
git_root="$(git rev-parse --show-toplevel 2>/dev/null)"
script_dir=$(dirname "$(readlink -f "$0")")
@pythoninthegrass
pythoninthegrass / Dockerfile.deadsnakes
Last active July 11, 2024 18:59 — forked from BillRaymond/gist:b39ae5d862aa81a250b70b812bd5d1cc
Dockerfile to build a specific version of Python and set it as the default using Deadsnakes
# syntax=docker/dockerfile:1.7
FROM ubuntu:20.04
ARG PYTHON_VERSION="3.11"
ENV TZ=US/Chicago
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
#!/usr/bin/env bash
@pythoninthegrass
pythoninthegrass / input_timeout.py
Created July 8, 2024 21:04
Use python signals to enforce a user input timeout
#!/usr/bin/env python
import sys
import signal
timeout = 5 # Timeout in seconds
def handle_timeout(signum, frame):
raise TimeoutError("Input timed out!")
@pythoninthegrass
pythoninthegrass / get_secrets.py
Last active June 24, 2024 22:31
Snippet from an env role to generate programmatic .env files via the `get_secrets.py` script
...
@log_call
def file_exists(filename):
"""Check if a file exists."""
fn = Path.cwd() / filename
if fn.exists():
overwrite = input(f"File '{filename}' already exists. Do you want to overwrite it? (y/n): ")
match overwrite.lower():
case "y" | "yes":
fn.touch(exist_ok=True)
@pythoninthegrass
pythoninthegrass / main.py
Last active June 23, 2024 00:01
geopy test file
#!/usr/bin/env python
import os
from geopy.geocoders import Nominatim
from pprint import pprint
app = Nominatim(user_agent="tutorial")
if len(os.sys.argv) > 1:
your_loc = os.sys.argv[1]