Skip to content

Instantly share code, notes, and snippets.

@jsundram
jsundram / color_names.py
Last active January 31, 2025 05:10
Trying to find names for colors. Takes the html code for a color (e.g. "#30c5ff" and finds the closest XKCD color name (https://xkcd.com/color/rgb/ and https://blog.xkcd.com/2010/05/03/color-survey-results/)
from matplotlib.colors import hex2color, rgb_to_hsv, XKCD_COLORS, CSS4_COLORS
import matplotlib.pyplot as plt
import numpy as np
class ColorNames:
def __init__(self, color_dict, converter=hex2color):
"""
color dict: A map of names to hex values.
converter: A function that takes a hex color and returns an array.
@jsundram
jsundram / rainbow.py
Created January 27, 2025 05:57
multicolored text strings in matplotlib / python
import matplotlib.pyplot as plt
from matplotlib import transforms
# See https://stackoverflow.com/a/79389836/2683
plt.style.use('classic')
def multicolored_text(x, y, text, cd, **kw):
"""
Place text at (x, y) with colors for each word specified in the color
dictionary cd, which maps strings to colors, and must include a 'default'
@jsundram
jsundram / get_checkins.py
Last active February 19, 2024 00:30
Get my Swarm checkins from Foursquare
import requests
from datetime import datetime
import json
"""
Instructions:
1. go to https://swarmapp.com/history
2. open developer tools in browser, and navigate to the "network" tab.
3. filter for fetch/XHR
4. select a month in the dropdown
@jsundram
jsundram / Haydn-076_2-wp4tet.md
Created January 16, 2024 20:03
Haydn: String Quartet in d, Op 76 Nr. 2 Program Notes from Willow Pond String Quartet 1997 concert (from https://www.bobrej.com/picnic/1997.htm)

Haydn: String Quartet in d, Op 76 Nr. 2 "Quinten"

  1. Allegro
  2. Andante o più tosto Allegretto
  3. Menuetto
  4. Finale. Vivace assai

haydn - wpq

Of humble origins, Franz Joseph Haydn was born in Rohrau, near Vienna, on 31 March 1732. When eight years old he was accepted into the choir school of Saint Stephen's Cathedral in Vienna, where he received his only formal education. Dismissed from the choir at the age of seventeen, when his voice broke, he spent the next several years as a struggling freelance musician. In 1755 Haydn was engaged briefly by Baron Karl Josef von Fürnberg, for whom he apparently composed his first string quartets. Haydn's marriage in 1760 to Maria Anna Keller proved to be unhappy. The turning point in Haydn's fortunes came in 1761, when he was appointed assistant music director to Prince Pál Antal Esterházy; a year later he became full director. As Kapellmeister, Haydn served under the patronage of thre

@jsundram
jsundram / Haydn-020_4-wp4tet.md
Last active January 16, 2024 20:03
Haydn: String Quartet in D, Op 20 Nr. 4 Program Notes from Willow Pond String Quartet 1996 concert (from https://www.bobrej.com/picnic/1996.htm)

Haydn: String Quartet in D, Op 20 Nr. 4

  1. Allegro di molto
  2. Un poco Adagio affettuoso (Theme with variations)
  3. Menuetto: Allegretto all zingarese
  4. Finale. Presto scherzando

haydn - wpq

Of humble origins, Franz Joseph Haydn was born in the village of Rohrau, near Vienna, on March 31, 1732. When eight years old he was accepted into the choir school of Saint Stephen's Cathedral in Vienna, where he received his only formal education. Dismissed from the choir at the age of seventeen, when his voice broke, he spent the next several years as a struggling freelance musician. He studied on his own the standard textbooks on counterpoint and took occasional lessons from the noted Italian singing master and composer Nicola Porpora. In 1755 Haydn was engaged briefly by Baron Karl Josef von Fürnberg, for whom he apparently composed his first string quartets. Haydn's marriage in 1760 to Maria Anna Keller proved to be unhappy.

@jsundram
jsundram / github-pandoc.css
Last active January 13, 2024 20:49 — forked from dashed/github-pandoc.css
Forked copy, incorporating changes suggested on the comment thread from @timfoster and @nightroman (`55em` vs `44em` and `overflow-x: scroll;`). Use as follows: `pandoc -s -f gfm -t html5 -o readme.html README.md -c github-pandoc.css`
/*! normalize.css v2.1.3 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 8/9.
*/
@jsundram
jsundram / connections.py
Created November 17, 2023 20:23
Use word embeddings to generate better guesses at NYT Connections. TODO: come up with an algorithm to actually solve connections... https://www.nytimes.com/games/connections
from collections import defaultdict
from scipy import spatial
from sklearn.manifold import TSNE
from sklearn.cluster import SpectralClustering, KMeans
import functools
import heapq
import matplotlib.pyplot as plt
import numpy as np
import os
@jsundram
jsundram / boxed.py
Last active November 16, 2023 22:10
Solve the NY Times' Letter Boxed game in 2 guesses (modified version of KV's code/algorithm)
from time import time
import re
import sys
def get_words(filename='words.txt'):
# https://raw.githubusercontent.com/dwyl/english-words/master/words.txt
with open(filename) as f:
return [line.strip() for line in f]
@jsundram
jsundram / README.md
Last active November 18, 2024 15:44

MDB Excavation

MDB is a Microsoft Access Database file. We'd like to look inside of it, but we have a Mac and no MS Office license.

export.py is a program that can do each of the following:

  1. Put each table into its own .csv file to look at.
  2. Put each table in the data into an excel / google sheets doc for easy viewing/browsing
  3. Create a sqlite db which is similarly portable but accessible via a variety of common tools
@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