Skip to content

Instantly share code, notes, and snippets.

@jsundram
jsundram / nato.py
Last active October 16, 2023 19:18
Spell out a word (or string) in the Nato Alphabet, in an output format suitable for piping to the MacOS "say" command
import sys
# from https://www.worldometers.info/languages/nato-phonetic-alphabet/
TABLE = """
A Alfa/Alpha ● ▬ AL FAH
B Bravo ▬ ● ● ● BRAH VOH
C Charlie ▬ ● ▬ ● CHAR LEE
D Delta ▬ ● ● DELL TAH
E Echo .● ECK OH
F Foxtrot ● ● ▬ ● FOKS TROT
@jsundram
jsundram / wordle_stats_viz.py
Last active October 6, 2023 19:39
letter statistics visualizations for wordle (using the short wordle wordlist)
from collections import Counter
from string import ascii_lowercase as ALPHABET
import json
import matplotlib.pyplot as plt
import numpy as np
"""
For https://www.powerlanguage.co.uk/wordle/.
Read more here: https://www.nytimes.com/2022/01/03/technology/wordle-word-game-creator.html
"""
@jsundram
jsundram / setup.sh
Last active July 3, 2023 13:34 — forked from bradp/setup.sh
New Mac Setup Script
# forked from https://gist.github.com/bradp/bea75b16d3325f5c47d4
# usage:
# 1) attach ssd to old machine and start running backup.sh
# 2) grab the latest version of this file from
# https://gist.github.com/jsundram/eeca472a8929bfab27209783b16bd6d9
# 3) copy this script onto the new machine and start running it
# sh setup.sh
# you will need to add homebrew to your .zprofile path
# PATH=$PATH:/opt/homebrew/bin
# echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zprofile
@jsundram
jsundram / cull.py
Last active April 5, 2023 15:22
Check if lat long is inside the bounds of the continental US (box model, not shape)
# http://en.wikipedia.org/wiki/Extreme_points_of_the_United_States#Westernmost
top = 49.3457868 # north lat
left = -124.7844079 # west long
right = -66.9513812 # east long
bottom = 24.7433195 # south lat
def cull(latlngs):
""" Accepts a list of lat/lng tuples.
returns the list of tuples that are within the bounding box for the US.
NB. THESE ARE NOT NECESSARILY WITHIN THE US BORDERS!
@jsundram
jsundram / bee.sh
Last active November 4, 2022 18:17
Solving the Spelling Bee (https://www.nytimes.com/puzzles/spelling-bee) with a one-liner in Bash
#!/usr/bin/env bash
# Solve the Spelling Bee (https://www.nytimes.com/puzzles/spelling-bee)
# Usage `./bee.sh ulroapn | more` where the first letter is the one in the middle
# Output: a list of valid dictionary words that contain the first letter and
# no letters that aren't on the list provided.
# Unfortunately the MacOS dictionary has words that aren't in the custom
# Spelling Bee dictionary, so you may find words listed that aren't accepted
@jsundram
jsundram / howtolog.md
Last active August 28, 2022 22:53
How to make a chamber music log (or any other kind of information) using google forms

How to Make a Chamber Music Log

  1. Go to Google Forms https://docs.google.com/forms/u/0/

  2. Create new Form

  3. Screenshot 2017-05-31 11 55 03
    1. Fill it out with the questions that you might like to have. Mine looks like this:
    2. Screenshot 2017-05-31 12 17 39
  4. Click Responses

"""
Takes a Met Opera json file and parses it and then writes a .inf file suitable for creating video chapters.
ffmpeg -i opera.mp4 -i opera.json.inf -map_metadata 1 -codec copy new_opera.mp4
"""
import json
import sys
from datetime import datetime
@jsundram
jsundram / hex_to_latex.py
Last active June 17, 2022 21:44
Convert a HEX color to LateX Color Spec. Useful for taking colors from any site and producing output suitable for e.g. http://latexcolor.com/
def hex_to_latex(c, name="name"):
""" Input: a hex color like "#B29155" ('#' is optional)
Output: \definecolor{name}{rgb}{0.70, 0.16, 0.57}
"""
if c.startswith("#"):
c = c[1:7]
r, g, b = [(int(c[ix:ix+2], base=16) / 255) for ix in range(0, 6, 2)]
return '\definecolor{%s}{rgb}{%1.2f, %1.2f, %1.2f}' % (name, r, g, b)