Skip to content

Instantly share code, notes, and snippets.

View alanbernstein's full-sized avatar

Alan Bernstein alanbernstein

View GitHub Profile
@alanbernstein
alanbernstein / mplpersist.json
Last active February 28, 2023 23:46
Matplotlib PersistentFigure prototype
{"alans-desktop-some-script.py-main-Figure 1": [2485, 231, 1054, 862]}
@alanbernstein
alanbernstein / pqli.py
Created April 8, 2022 17:38
PQL+CLI - a simple local pilosa client
#!/usr/bin/env python3
import argparse
import json
import random
import requests
import time
#from plotly.offline import plot
#import plotly.graph_objs as go
@alanbernstein
alanbernstein / phylo.py
Last active November 11, 2021 04:20
phylo.py
#!/usr/local/bin/python
import sys
import wikipedia
import requests
import re
from pprint import pprint
# TODO: cache results and use cache to build up a tree
# TODO: handle disambiguation page (e.g., for 'orange')
@alanbernstein
alanbernstein / music_theory.py
Created May 22, 2021 04:57 — forked from mvanga/music_theory.py
Basic Music Theory in ~200 Lines of Python
# The code for my article with the same name. You can find it at the URL below:
# https://www.mvanga.com/blog/basic-music-theory-in-200-lines-of-python
# MIT License
#
# Copyright (c) 2021 Manohar Vanga
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@alanbernstein
alanbernstein / crunchberry_vis.py
Created April 27, 2021 18:21
Are Texas-sized crunchberries really 3x as big?
from collections import defaultdict
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox
normal_samples_min_max_diam = [
[12, 14],
[13, 15],
[12, 15],
@alanbernstein
alanbernstein / fillet_demo.py
Last active February 14, 2021 07:24
simple fillet example with numpy
from matplotlib import pyplot as plt
import numpy as np
from shapely.geometry import Polygon
from ipdb import set_trace as db
def main():
fillet_demo()
@alanbernstein
alanbernstein / border-sample-australia.json
Created February 10, 2021 05:11
polyline smoothing attempts
[[55.60458963143672, 6.344134770404208], [55.6254632267828, 6.337129830206686], [55.60910039087562, 6.229813623881452], [55.62319315158302, 6.177102890074548], [55.599799681727454, 6.112288249833094], [55.6197243031257, 6.085758465395703], [55.57500185675112, 6.037293331710632], [55.57972586711283, 5.99042398847148], [55.531475137494226, 5.962734650863261], [55.460421247041275, 5.87334504507754], [55.43845503757297, 5.874789476632287], [55.38653276222971, 5.716568106677365], [55.34442623363374, 5.6649444409916905], [55.0906992233307, 5.521413353897024], [55.00428464574901, 5.444832031743397], [54.88500137356685, 5.403923196603118], [54.85919019379097, 5.373908570787792], [54.66938268686648, 5.3725558408613185], [54.58827630940152, 5.319732261307423], [54.52210828523082, 5.31060063116936], [54.45170456646131, 5.26900254435648], [54.43892241772447, 5.239180065187691], [54.430048050840036, 5.2568518437884455], [54.29608058774813, 5.205661074225492], [54.17762938393885, 5.122854327909668], [54.1250721254506, 5.05
@alanbernstein
alanbernstein / benford.py
Created January 24, 2021 20:19
charts for benford blog post
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
(44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
(148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
(227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
(188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
@alanbernstein
alanbernstein / jqurl
Created January 14, 2021 21:51
curl+jq have a baby
#!/bin/bash
# make an http request via curl
# try to decode it as json with jq
# if it works, pretty print the json
# if it doesn't, ugly print the response
F1="$HOME/tmp.curl"
F2="$HOME/tmp.jq"
curl -s $1 > $F1