Skip to content

Instantly share code, notes, and snippets.

View samclane's full-sized avatar

Sawyer McLane samclane

View GitHub Profile
@samclane
samclane / connectforhealthco_price_scraper.py
Last active June 14, 2021 16:18
Webscraper for public-market insurance prices from Connect for Health CO's website
import csv
import json
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from __future__ import annotations
from functools import reduce
from operator import add
from typing import Sequence, Union, Iterable, Any
NumberTypes = (int, float, complex,)
Number = Union[NumberTypes]
NestedSequences = Union[Number, Sequence['NestedSequences']]
@samclane
samclane / annotation_casting_class.py
Created August 19, 2020 20:38
A class and example sublclass that casts attributes to their annotated types
from typing import Dict, Any
class SelfCastingClass:
def __init__(self, **kwargs: Dict[str, Any]):
for k, v in kwargs.items():
self.__setattr__(k, self.__annotations__[k](v))
def __repr__(self):
return "{" + ", ".join([f"'{k}': {v.__repr__()}" for k, v in self.__dict__.items()]) + "}"

Keybase proof

I hereby claim:

  • I am samclane on github.
  • I am sawyermclane (https://keybase.io/sawyermclane) on keybase.
  • I have a public key ASAqk0V6tI-mw3FWMQwC_kv0KXlqEvIJeib4wsKWnWY8bAo

To claim this, I am signing this object:

@samclane
samclane / LoggedList.py
Created December 4, 2019 17:52
List with access logging. Lets you see when items are read or written to.
class LoggedList(list):
def __init__(self, *args, name=None, **kwargs):
super().__init__(*args, **kwargs)
self._name = name
def __getitem__(self, item):
logging.info(f"{self._name} Getting item {item}")
super().__getitem__(item)
def __setitem__(self, key, value):
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
cd ~/Downloads/
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
tar -xvf Python-3.6.8.tgz
cd Python-3.6.8
./configure
make
@samclane
samclane / Lorenz.pde
Created August 1, 2019 20:54
Source for the "unraveled" Lorenz Attractor. https://youtu.be/GKNx47T7uFc
import peasy.*;
float x = 0.01;
float y = 0;
float z = 0;
float a = 10;
float b = 28;
float c = 8./3.;
@samclane
samclane / AAAA.pde
Created July 21, 2019 06:33
Recreating /u/f-x-p-x's AAA animation. All credit goes to them.
/*
Recreating /u/f-x-p-x's AAA animation.
Requires OpenSimplexNoise.java:
https://github.com/CodingTrain/website/blob/master/CodingChallenges/CC_137_4D_Noise_Loop/Processing/CC_137_4D_Noise_Loop/OpenSimplexNoise.java
*/
PGraphics pg;
float fontSize;
int cols = 30;
import numpy as np
import pixelhouse as ph
WIDTH = 255
HEIGHT = 255
COLOR = "#6639B7"
CIRCLE_SCALE_FACTOR = 1/65
def logo_animation():
A = ph.Animation(fps=60, duration=1.5, width=WIDTH, height=HEIGHT, bg=COLOR)
@samclane
samclane / ecs_delete_service.md
Created July 2, 2019 21:30
How to scale down an AWS ECS instance to 0 so it can be deleted
  1. Using service-definition.json, find the values of serviceName and cluster

  2. Run the following:

    aws ecs update-service --service <serviceName> --cluster <cluster> --desired-count 0

  3. This scales down the service to 0 so it can be stopped:

aws ecs delete-service --cluster <cluster> --service ``