## Color contrast checker

I made this color contrast checker. You can specify colors either by entering hex triplets (e.g. #00ffdd) or using your browser’s built-in color-selecting widget. It will compute the contrast ratio and determine if the color contrast meets the WCAG 2.1 accessibility success criterion 1.4.3 (AA) or 1.4.6 (AAA). Color contrast checker Source code (Codeberg) (MIT License)

## Now on Hackyderm

I have an account on the Mastodon instance Hackyderm now! @chrisphan@hackyderm.io

## Code to make treemap

Earlier this week I posted about this treemap I made. (Interactive version) Today, I have placed the code to produce this treemap in a Codeberg repo. It’s not the most beautiful code in the world. (If I were really ambitious, I’d turn it into a proper library.)

## This is America

This is a treemap of every county (or county equivalent) in the United States, where the area of each rectangle is proportional to the population of the corresponding county. Counties that are part of the same core-based statistical area are grouped together. (These have a thicker green border.) Moreover, core-based statistical areas that belong to the same combined statistical area are grouped together. (CSAs have an even-thicker red border.) For example, the red rectangle in the upper-left corner represents the New York-Newark, NY-NJ-CT-PA CSA:

## Silly Decorator #2: @plus_one

It’s like a off-by-one error on your wedding day. >>> from plusonedecorator import plus_one >>> @plus_one ... def cost(quantity: int, marginal_cost: float) -> float: ... """Compute the cost of production.""" ... return quantity * marginal_cost ... >>> cost(1000, 0.25) 251.0 >>> @plus_one ... def invite(name: str, pronoun: str) -> str: ... """Decide to invite someone to your wedding.""" ... return f"Let's be sure to invite {name} and {pronoun}." ... >>> invite("Emilia", "her") "Let's be sure to invite Emilia and her plus one.

## Silly Decorator #1: @a_hole

I’m like a pâtissier, except I decorate functions instead of cakes, and I decorate with U+1F4A9 instead of frosting. >>> from aholedecorator import a_hole >>> @a_hole ... def hello(name: str = "friend") -> str: ... return f"Hello {name}, I hope you are well." ... >>> hello() 'Hello friend, I hope you are well.' >>> hello() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/chris/Documents/projects/gists/a_hole_decorator/aholedecorator.py", line 70, in new_func raise AHoleError(choice(_MESSAGES)) aholedecorator.

## Hexagonal snowflakes

body { background-color: black; } div.pic { width: 30vw; background-color:#555555; margin: 2vw; padding: 1vw; color: white; } div.pic_set{ display: flex; flex-flow: row wrap; } div.pic_set_elt{ flex: 2; } div.widepic { width: 60vw; background-color:#555555; margin: 2vw; } A hexagonal paper snowflake Remember back in elementary school, where you made paper snowflakes by folding a square piece of paper into a small triangle and then cut notches into it?

## mypy sum error

Recently, I’ve been exploring the type hints functionality in Python. The other day, I ran across what I think is a bug (already known) in mypy. Here is a minimal working example of the issue I came across: 1 2 3 4 from fractions import Fraction my_value = 1 + sum([Fraction(k + 1, 5 ** k) for k in range(5)]) print(f"The result is {my_value}.") This program runs as you would expect.

## SArCAsTic cApiTalIZatioN GeNerATOr

Here’s another fun thing I made. GitHub repo