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 / 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kcarnold
kcarnold / email-to-printer.applescript
Created November 12, 2019 22:37
AppleScript to email a PDF to the Calvin University print queue (use with "Run AppleScript" action in Automator, in either a Print Plugin or a Quick Action)
on run {input, parameters}
set PDFs to input
set msubject to "to print: "
repeat with aFile in PDFs
tell application "Finder"
set filename to ((name of aFile) as string)
end tell
set msubject to msubject & filename & ","
end repeat
tell application "Microsoft Outlook"
@kcarnold
kcarnold / blacken_notebook.py
Created November 2, 2018 19:59
Format all code in a notebook with Black
# https://black.readthedocs.io/en/stable/
import json
import black
import re
magic_re = re.compile(r'^%', flags=re.MULTILINE)
ipymagic = '##IpyMagic##'
filename = 'notebook.ipynb'
@kcarnold
kcarnold / incremental_moments.py
Created July 16, 2015 22:05
Incremental Moments
import numpy as np
class IncrementalMoments(object):
'''Knuth's incremental mean and variance computation, applied elementwise.'''
def __init__(self, shape, initial_items=[]):
self.n = 0
self.mean = np.zeros(shape)
self.m2 = np.zeros(shape)
self.update_seq(initial_items)
@kcarnold
kcarnold / README.md
Last active August 29, 2015 14:17
Affinity propagation