Skip to content

Instantly share code, notes, and snippets.

View kcarnold's full-sized avatar

Kenneth C. Arnold kcarnold

  • Grand Rapids, MI
View GitHub Profile
@kcarnold
kcarnold / streamlit_predictive_text.py
Last active April 30, 2024 12:08
Streamlit buttons-to-insert-words (predictive text) demo
import streamlit as st
import random
words = ['hello', 'world', 'goodbye', 'moon']
random.shuffle(words)
essay = st.text_area("Essay", "", key="essay")
def append_word(word):
st.session_state['essay'] = (
@kcarnold
kcarnold / recipes.py
Created December 2, 2023 20:27
Recipe generator - Streamlit + OpenAI chatcompletions
import streamlit as st
import os
from openai import OpenAI
# load the API key from a .env file
from dotenv import load_dotenv
load_dotenv()
st.title("Recipe Finder")
@kcarnold
kcarnold / core-double-counts.js
Created October 17, 2023 18:52
core double counts
// Run this on the Core Curriculum page
// Gather courses by section
courses = new Map();
document.querySelectorAll('.acalog-course').forEach(x => {
let name = x.textContent;
let section = x.closest('.acalog-core').querySelector('h3, h4').textContent;
console.log(name, section);
if (!courses.has(name)) {courses.set(name, [])}
courses.get(name).push(section);
});
@kcarnold
kcarnold / fix-plotly-size.js
Created September 16, 2023 14:52
Quarto plugin to hotfix Plotly plot sizing
window.FixPlotlySize = {
id: 'FixPlotlySize',
init: function(Reveal) {
Reveal.addEventListener( 'slidechanged', function( event ) {
let curSlide = Reveal.getCurrentSlide();
require(['plotly'], function(Plotly) {
let plotlyDivs = curSlide.querySelectorAll('.js-plotly-plot');
for (let i = 0; i < plotlyDivs.length; i++) {
Plotly.Plots.resize(plotlyDivs[i]);
}
@kcarnold
kcarnold / Comment Insertion updated version.WORD.yaml
Created June 26, 2023 14:35
Update: inserting comments on words that are loaded from a infoList from the (fake) server
name: Comment Insertion updated version
description: >-
Update: inserting comments on words that are loaded from a infoList from the
(fake) server
host: WORD
api_set: {}
script:
content: |
// Given the target word and the comment, insert an anchored comment.
function addComment(paragraphIndex: number, targetWord: any) {
@kcarnold
kcarnold / README.md
Last active May 25, 2023 22:43
SentenceTransformer embeddings of a sample of Quora Duplicate Questions
@kcarnold
kcarnold / video-subtitles-via-whisper.py
Last active October 25, 2022 16:08 — forked from rasbt/video-subtitles-via-whisper.py
Script that creates subtitles (closed captions) for all MP4 video files in your current directory
# Sebastian Raschka 09/24/2022
# Fixed to avoid problems with spaces and other special characters in filenames, Ken Arnold 10/25/2022
#
# Create a new conda environment and packages
# conda create -n whisper python=3.9
# conda activate whisper
# conda install mlxtend -c conda-forge
# Install ffmpeg
# macOS & homebrew
@kcarnold
kcarnold / aiosched.py
Created April 9, 2022 15:22
Integrating Python's sched module with asyncio
import sched
import time
import asyncio
import datetime
start_time = time.time()
def tick(a='default'):
print("From tick", time.time() - start_time, a)
@kcarnold
kcarnold / sort_names.py
Created May 13, 2020 16:02
Sort a list of names alphabetically by last name (from clipboard)
print(
', '.join(
sorted(
subprocess.check_output('pbpaste').decode('utf-8').split('\n'),
key=lambda name: name.split()[-1])
)
)
@kcarnold
kcarnold / vecpile.py
Created February 29, 2020 20:25
VecPile
class VecPile:
"""An attribute-accesed collection that asserts that all of its elements have the same length.
Useful for keeping several collections together, such as vectors with labels, or several different representations of the same data."""
def __init__(self, **kw):
for k, v in kw.items():
setattr(self, k, v)
@staticmethod