Skip to content

Instantly share code, notes, and snippets.

@andrewbolster
andrewbolster / main.py
Created April 21, 2024 16:40
Better Statement Generator
import typing as t
import logging
import random
from fastapi import Depends, FastAPI, Header, HTTPException
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel
from starlette import status
from os import environ
import nltk
import random
from nltk.corpus import brown
# Ensure the necessary NLTK resources are downloaded
nltk.download('brown')
nltk.download('universal_tagset')
def get_common_words_by_pos(tag, num_words=100):
""" Return a list of the most common words for a given part of speech tag """
@andrewbolster
andrewbolster / migrate_ownership.py
Created February 2, 2024 15:23
As part of a Atlassian merge+migration where we needed to have all _old_ useraccounts manually migrate their content to _new_ user accounts, to then have the whole instance merged, I didn't want to go through 300 pages of updates. So I wrote this.
from tqdm.auto import tqdm
from requests.exceptions import HTTPError
from getpass import getpass
import os
from atlassian import Confluence
def get(label):
if label not in os.environ:
os.environ[label]=getpass(f'Enter {label}')
@andrewbolster
andrewbolster / Random Three Vector.py
Last active August 5, 2023 11:58
Generate a random 3D unit vector with uniform spherical distribution
def random_three_vector():
"""
Generates a random 3D unit vector (direction) with a uniform spherical distribution
Algo from http://stackoverflow.com/questions/5408276/python-uniform-spherical-distribution
:return:
"""
phi = np.random.uniform(0,np.pi*2)
costheta = np.random.uniform(-1,1)
theta = np.arccos( costheta )
@andrewbolster
andrewbolster / observium_discoverer
Created April 24, 2015 15:02
SNMP Monitoring and Configuration for Networks and Linux Host Monitoring
# Note: This file lives on the observium server inside /etc/cron.d/
13 * * * * root host -t axfr anrg.liv.ac.uk | awk '$4 ~ "^A$" {print $1}' > /dev/shm/devices 2> /dev/null; /opt/observium/add_device.php /dev/shm/devices >> /dev/null 2>&1
@andrewbolster
andrewbolster / fuvm.py
Created January 18, 2022 13:17
How to log when connections drop.
"""usage
python fuvm.py <external canary URL>
"""
import time
import socket
import requests
import sys
import logging
class CustomFormatter(logging.Formatter):
#!/bin/bash
# Example script to start up tunnel with autossh.
# This script will tunnel 22 from the local host
# to 11122 on the remote host. If that post isn't
# availabile it'll increment. Also does the same
# with 8888/11188 for ipython notebook
# REQUIRED autossh
HOST=${@: -1}
REMOTE_SSH_PORT=11122
REMOTE_HTTP_PORT=11188
@andrewbolster
andrewbolster / import_repo.sh
Last active June 23, 2020 14:25
Git Merge Hellscape
#!/bin/bash
usage() {
cat << EOF
This script imports a git repo (accessible from https://\$origin/\$user/\$repo) and all its history as subdirectory of a destination (available locally at \$dest)
It is designed for non-production, archival processes and may destroy everything you've ever loved because you looked at it funny. You have been warned.
The structure of the destination will end up something like this:
~/src
- \$dest
- origins
@andrewbolster
andrewbolster / motion.conf
Created January 11, 2014 16:27
Motion Configuration file use by Farset Labs
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 3.2.11
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
@andrewbolster
andrewbolster / eventcamsort
Created January 11, 2014 16:42
Event Cam Management script
#!/bin/bash
BASE="/mnt/eventcam/"
COMPRESS=0
RERUN=0
UPLOAD=1
TODAY=`date +%Y%m%d`
# Move all jpgs in to per date folder for processing
for file in `find $BASE -maxdepth 1 -name '*.jpg' -type f -print`; do
newfilename=`echo $file | awk -F '-' '{print $2$3}'`
date=`echo $newfilename | cut -c 1-8`