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/", 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.

What size are national legislatures?

Introduction The other day, I came across something called the “cube root rule”, which is a proposed reform to the size of the U.S. House of Representative. Since 1913, the size of the U.S. House has remained constant at 435 seats (except for a few years when two seats were temporarily added to accommodate the addition of Alaska and Hawaii). Under the cube root rule, the size of the U.

On (not) voting at a polling place

Because of the potential for COVID-19 to disrupt elections this fall, mail voting is getting a lot of attention. It’s not a good idea to make people choose between their safety and exercising the franchise. I grew up in Oregon, and spent the first decade of my adult life there, but now I have spent more of my adult life living outside Oregon than within it. Since moving from Oregon, I have shed many of my Oregonian habits: I have become used to pumping my own gas.

Giving up Celsius

When I was in elementary school, I came across a series of books in the school library about the metric system. I don’t remember the title or the author, but I do remember reading each of them and falling in love with the measurement system used by almost every country in the world other than my own. The advantages of the metric system, especially ease of conversion between units, are well-known, and I won’t belabor them here.

Bugs in the iOS calendar app

Stand-up mathematician1 Matt Parker found some interesting bugs in the iOS calendar app: I encourage you to watch the video, but the short summary is that if you scroll back far enough (centuries) in the year view of the iOS Calendar app, the year labels and some months disappear. I reproduced this bug on my iPhone: My iPhone’s calendar app year view for 1582 is messed up.