Skip to content

Instantly share code, notes, and snippets.

View kylemcdonald's full-sized avatar

Kyle McDonald kylemcdonald

View GitHub Profile
@kylemcdonald
kylemcdonald / matplotlib Border Removal.ipynb
Last active January 25, 2025 13:07
How to (mostly) remove all borders and padding with matplotlib.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / download-urls.py
Last active January 17, 2025 04:56
Download a range of URLs in parallel.
from multiprocessing.dummy import Pool
from tqdm import tqdm
from urllib.parse import urlsplit
import urllib3
import itertools, functools, operator
import os
import sys
import re
import errno
import argparse
@kylemcdonald
kylemcdonald / function-calling.ipynb
Created June 14, 2023 01:10
Example of OpenAI function calling API to extract data from LAPD newsroom articles.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / showarray.py
Created January 3, 2016 08:56
Minimal code for rendering a numpy array as an image in a Jupyter notebook in memory. Borrowed from the Deep Dream notebook.
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(a)
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
IPython.display.display(IPython.display.Image(data=f.getvalue()))
@kylemcdonald
kylemcdonald / Line Segment Intersection.ipynb
Created July 2, 2019 18:49
Python Line Segment Intersection example.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / Interprocess Queue Performance.ipynb
Created September 8, 2019 15:10
Testing the performance of Queue-based IPC in Python 3.7.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / Voyager 1 Decode.ipynb
Created August 7, 2015 16:46
Voyager 1 Decoding
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / list-compute-engines.sh
Created July 4, 2024 20:17
List all compute engine instances on Google Cloud.
#!/usr/bin/env bash
# List all projects
projects=$(gcloud projects list --format="value(projectId)")
# Function to check if Compute Engine API is enabled
is_compute_api_enabled() {
local project=$1
gcloud services list --enabled --project="$project" --format="value(config.name)" | grep -q "compute.googleapis.com"
}
@kylemcdonald
kylemcdonald / Collect Parler Metadata.ipynb
Last active June 27, 2024 04:09
Collect video URLs and GPS data for Parler videos.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / convert.py
Last active May 25, 2024 19:24
Scrape ShaderToy. Instead of running this, consider downloading the files from here: https://goo.gl/MWGvkL Or if you want to do more work with ShaderToy data, consider using their API https://www.shadertoy.com/api
# !/usr/bin/env python
import os, re, argparse, json
parser = argparse.ArgumentParser(
description='Extract code from ShaderToy json.')
parser.add_argument('input')
parser.add_argument('output')
args = parser.parse_args()