Skip to content

Instantly share code, notes, and snippets.

View swenson's full-sized avatar
🍰
cupcake

Christopher Swenson swenson

🍰
cupcake
View GitHub Profile
@swenson
swenson / clean.py
Last active August 3, 2024 21:51
Script to cleanup SRT transcripts. Run like `python3 clean.py input.srt output.srt`
from collections import namedtuple
from pprint import pprint
import math
import sys
Caption = namedtuple('Caption', ['start', 'end', 'text'])
def parse(l):
lines = l.split('\n')
@swenson
swenson / make-subtitles.sh
Created November 4, 2023 23:27
Quick and dirty script to find files with missing subtitles and transcribe them with whisper.cpp -- requires ffmpeg and whisper.cpp. Run like: python3 transcribe-missing.py path/to/media/files
#!/bin/bash
set -euxo pipefail
echo "Converting audio"
rm -f temp.wav
ffmpeg -i "$1" -ar 16000 -ac 1 -c:a pcm_s16le temp.wav
echo "Transcribing"
./main -m models/ggml-base.en.bin -f ./temp.wav --output-srt -t 8 -ml 42
mv temp.wav.srt "${1%.*}.en.srt"
# optional: rewrite the original file to include subtitles
@swenson
swenson / add-subtitles.sh
Last active April 28, 2023 20:27
Add subtitles to a video using whisper.cpp and ffmpeg. (./main is the whisper.cpp main binary.) https://github.com/ggerganov/whisper.cpp
#!/bin/bash
echo "Converting audio"
rm -f temp.wav
ffmpeg -i "$1" -ar 16000 -ac 1 -c:a pcm_s16le temp.wav
echo "Transcribing"
./main -m models/ggml-base.en.bin -f ./temp.wav --output-srt
echo "Adding to video file"
ffmpeg -i "$1" -i temp.wav.srt -c copy -metadata:s:s:0 language=eng "${1%.*}.subtitled.mkv"
@swenson
swenson / git-fanfic-setup.sh
Created June 12, 2020 19:52
Setup git fanfic aliases
#!/bin/sh
# thanks hanselman https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx
git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/canon'
# https://twitter.com/tesseralis/status/1271197776886370305
git config --global alias.retcon 'rebase'
git config --global alias.op 'blame'
git config --global alias.clip-show 'log'
git config --global alias.fanfic 'branch'
@swenson
swenson / helloworld.bf
Created June 7, 2017 22:38
Hello World in BF, made in a diff with only line deletions
+
+
+
+
+
+
+
+
[
>
@swenson
swenson / life.py
Last active April 27, 2017 17:36
Game of Life in Rust and Python
from pprint import pprint
import random
def nextgen(state):
new_state = []
for i in range(5):
new_state.append([0] * 5)
for x in range(5):
@swenson
swenson / rlwe-integers.ipynb
Created December 24, 2016 07:57
This notebook performs computations from "Fully Homomorphic Encryption over the Integers" by van Dijk, Gentry, Halevi, and Vaikuntanathanm, which can be found at https://eprint.iacr.org/2009/616.pdf
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@swenson
swenson / explore.py
Created August 10, 2016 22:09
Ctags + Pygments static source generator
from collections import defaultdict
import json
import os
import os.path
import shutil
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_for_filename
from pygments import highlight
@swenson
swenson / segfault.py
Created July 13, 2016 04:23
Segfault Python 2.7.11 (mac) by adding numbers
This file has been truncated, but you can view the full file.
def f():
a0 = 0
a1 = 1
a2 = 2
a3 = 3
a4 = 4
a5 = 5
a6 = 6
a7 = 7
a8 = 8
@swenson
swenson / repro.chpl
Created March 28, 2016 21:44
Tuple destructor: formal count does not match argument count
proc f() : (int, int) {
return f();
}
proc main() {
f();
}