Skip to content

Instantly share code, notes, and snippets.

@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):
@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 / 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 / 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}')
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 / 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