Skip to content

Instantly share code, notes, and snippets.

@robert-mcdermott
robert-mcdermott / website-content-scrape.py
Last active January 12, 2025 13:21
Recursive website content scrape
import os
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
def is_valid(url, base_url):
parsed = urlparse(url)
return bool(parsed.netloc) and parsed.netloc == urlparse(base_url).netloc
def is_binary(url):
@robert-mcdermott
robert-mcdermott / chat-ollama-langchain.py
Created October 8, 2023 23:12
chatting with local ollama using langchain
from langchain.chat_models import ChatOllama
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.schema import HumanMessage
chat_model = ChatOllama(model="mistral", base_url = "http://localhost:11434", callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]))
#chat_model = ChatOllama(model="mistral")
messages = [
HumanMessage(content="Why is the sky blue?")
@robert-mcdermott
robert-mcdermott / print-embeddings.py
Created October 3, 2023 06:46
Print sentence vector embeddings
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
embeddings = model.encode("A fat tuxedo cat")
print(embeddings)
@robert-mcdermott
robert-mcdermott / sentence-similarity.py
Last active October 3, 2023 05:27
sentence-similarity.py
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer('all-MiniLM-L6-v2')
# Two lists of sentences
sentences1 = ['The cat sits outside',
'A man is playing guitar',
'The new movie is awesome',
'Jim can run very fast',
'My goldfish is hungry']
import boto3
def main():
organizations_client = boto3.client("organizations")
list_accounts_object = organizations_client.list_accounts()
all_accounts = []
accounts = list_accounts_object["Accounts"]
while "NextToken" in list_accounts_object:
#!/usr/bin/python
import os, socket, sys, time
socket.setdefaulttimeout(10)
start = time.time()
subnets = ['140.107.42','140.107.43','140.107.88','140.107.89','140.107.134',\
'140.107.135','140.107.52','140.107.53','140.107.152','140.107.153',\
'140.107.170','140.107.171']
scanips = []; hosts = []; vhosts = []; free = []; vfree = []; reclaim = []; squatters = []
#!/usr/bin/env python3
"""
Alternate account naming rules
Rule 1: firstname + lastname is less 18 or less characters long total
== firstname + "." + lastname (john.doe)
if conflict, check if rule 2 format (below) is available. If so use it
== firstname_initial + "." + lastname (j.doe)
if not, append an integer (starting with 2) to the end of the username
=== firstname + "." + lastname + int (john.doe2)
@robert-mcdermott
robert-mcdermott / FHCC-username-generator.py
Created December 2, 2021 02:58
Username and Email address generation script
#!/usr/bin/env python3
"""
Account naming rules
Rule 1: firstname + lastname is less 18 or less characters long total
== firstname + "." + lastname (john.doe)
if conflict append an integer (starting with 2) to the end of the username
=== firstname + "." + lastname + int (john.doe2)
Rule 2: firstname + lastname is greater than 18 characters long total *and*
@robert-mcdermott
robert-mcdermott / separate-them.py
Last active May 13, 2020 17:23
separate-them.py
from PIL import Image
def main():
images = [[] for p in range(num_people)]
im = Image.open(image)
im = im.convert("RGB")
size = im.size
data = list(im.getdata())
for _ in range(int(len(data)/num_people)):
@robert-mcdermott
robert-mcdermott / contact-tracing.py
Created April 24, 2020 16:45
SITHVID20 Contract Tracing Challenge
from math import sqrt
from PIL import Image
def main():
img = Image.open("contact-tracing.png")
infected = get_color_coords(img, Ic)
healthy = get_color_coords(img, Hc)
contact = []
for i in infected: