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 / 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 / gist:cf74cd8e282443b43b8a
Created May 21, 2014 15:51
Google Interview Study Guide
Author unknown.
1.) Algorithm Complexity: You need to know Big-O. If you struggle with
basic big-O complexity analysis, then you are almost guaranteed not to
get hired.
For more information on Algorithms you can visit:
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=alg_index
2.) Coding: You should know at least one programming language really
well, and it should preferably be C++ or Java. C# is OK too, since
@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 / runTests.sh
Last active July 30, 2021 22:30
Run Android tests (returning with exit code 1 if they fail)
# Use whatever your test app directory is for ExampleTest, and whatever the
# package you are testing for com.example.test
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
pushd ExampleTest
# adb shell throws away the return value, so we have to hack do some magic
# see https://code.google.com/p/android/issues/detail?id=3254
@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 / backup.sh
Created August 12, 2015 05:17
Install tarsnap. Then, here's some stuff.
#!/bin/bash
NAME="something"
d=$(date "+%F--%H-%M-%S")
/usr/local/bin/tarsnap -c --keyfile /root/tarsnap.key --cachedir /usr/local/tarsnap-cache -f $NAME-backup-$d /etc /home /root /var
@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 / test_pep8.py
Last active October 4, 2017 18:08
Test for running PEP8 against all Python files. Useful to hook up to nose and as part of your CI. I modify PEP8 in two ways by default: don't enforce 4-spacing (I prefer 2-spacing), and use 100 for the default line length, because we don't use 80-column punch cards anymore. Licensed under CC0 (public domain): do what you want. http://creativecom…
"""Run PEP8 on all Python files in this directory and subdirectories as part of the tests."""
__author__ = 'Christopher Swenson'
__email__ = 'chris@caswenson.com'
__license__ = 'CC0 http://creativecommons.org/publicdomain/zero/1.0/'
import os
import os.path
import unittest
@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):