Blog

A smattering of my thoughts, essays, proofs, puzzles, and discoveries.

What is the carbon footprint of your EV, really?

Electric Vehicles are an attractive option for the environmentally conscious commuter chiefly due to their lack of exhaust pipe. But do EVs have a secret carbon footprint that is hidden away from us? The short answer is yes, but they are still largely better in this regard than traditional internal combustion engine vehicles. If you are considering buying an EV with carbon emissions as your primary concern, going electric is probably your best choice, but there are cases when a hybrid may actually be better (for now)!
Tags

Using an LED as a Photodiode

An LED is a device which takes in electricity and emits light. Some electronic components work in reverse: a speaker can be used as a microphone and a motor can be used as a generator. It is reasonable to ask then, “can we shine light on an LED to produce electricity?” The answer is a surprising yes! LEDs can be made to work as photovoltaics 1, but the reason you don’t see this in practice is that they are really bad photovoltaics. Still, we are able to use this effect in practice, and this trick could even save the hobbyist from having to buy more specialized components.
Tags

An Extension of a Probability Puzzle

Consider a unit square and uniformly pick two points on its perimeter. What is the probability that the line that connects these two points has length less than 1? I first came across this problem in the accompanying youtube video, and decided to investigate it with a bit more depth. If you ever wondered about the sum of squares of uniform distributions, or if you are an avid shape-rotator, this one’s for you.
Tags

Alternative Definitions of the Derivative

I claim that the three following definitions of the derivative are equivalent: $$f’(x) = \begin{cases} \displaystyle \lim_{c \to x} \frac{f(c) - f(x)}{c-x} & \text{(A)} \\[10pt] \displaystyle \lim_{h \to 0} \frac{f(x+h) - f(x)}{h} & \text{(B)} \\[10pt] \displaystyle \lim_{t \to 1} \frac{f(tx) - f(x)}{tx - x} & \text{(C)} \end{cases}$$ Most people who have taken a calculus course will be familiar with form B above, however there are contexts in which forms A and C are more convenient to use. Real analysis courses, for instance, often will prefer form A. In this post, I shall prove the equivalence claim.
Tags

Embedding a Python Application in uWSGI

WyWeb (my software that is running this website right now) uses uWSGI to communicate with the server. Previously, WyWeb was a loose collection of python files that needed to be run in a virtualenv and started with a separate uWSGI command and a configuration file. This was fine when WyWeb was fairly bare bones and only used by me, but as I began to expand its functionality, I wanted to easily share it with others. Having people clone a git repo, manage dependencies, manually set up systemd services, and configure a server is too much to ask. Luckily, I found uWSGI’s official documentation on how to embed a python script in a standalone binary! Unluckily, the instructions are out-of-date at best, objectively wrong at worst, and written in a tone so intolerable that I thought I had been catapulted back to the heckin’ epicsause year of our Lord 2010. Luckily for you I am recording my steps for success so that hopefully you can be spared the torment I have endured.
Tags

Detecting Power Outages

Millions of my fellow Texans were in crisis the week after Valentine’s day 2021. The weather was colder than it had been since Santa Anna marched his army to San Antonio, and the whole state was experiencing blackouts. But I was lucky. I had an exact record of precisely when the power shut off and was restored throughout this whole ordeal. How did this help me? It didn’t. But it was nice to know that my power outage notification system was working as intended.
Tags

Writing a Simple Notcurses Program

Notcurses is a modern TUI library written by Nick Black (who you may see around the net as dankamongmen or some equally dank designation). As Dank himself will tell you, the older ncurses library is beautifully documented, rigorously tested, and very well supported. It is, however, quite old tracing its history back to at least 1982, and as such lacks some modern features such as thread-safety. I had been using the venerable ncurses for my fireplace program - a use case that it was never designed to handle. Overall ncurses does a good job, but there is occasional tearing and artifacts. Notcurses solved all the graphical glitches beautifully, and performance was noticeably improved. The problem is that just about the only other person using notcurses is Nick Black himself, and while his documentation is extensive, it is mostly source code snippets with few examples. Hopefully this article will provide a nice jumping-off point for the absolute beginner.
Tags

Strange Spells

Since the beginning of time, man has desired power greater than he possesses alone, power greater still than that of his enemies, and - perhaps for some - power far surpassing that of his neighbor. To this end, the practice of magic is long and storied. Many practitioners kept their arts a secret and their knowledge is lost. Some published grimoires to spread their wisdom (or from a more cynical point of view, to make a quick buck) and because of their generosity (or greed) we are able to examine the magical practices of old. What can be found is surprising not in its grandeur and mystery, but in oddity and sometimes downright silliness.
Tags

On Substitution Ciphers

One of the first “real” programs I ever wrote would encrypt a message using a substitution cipher and (more impressively) decrypt an encoded message without knowing the encryption key. Perhaps the first thing I had to come up with was an algorithm to take a cipher key that was used to encode a message, and transform it so that it could then be used do decode the ciphertext back into plaintext. I was aware of ROT-13’s property that if applied once to the plaintext, and again to the output ciphertext, it would yield the original plaintext. That is, ROT-13 is its own inverse. However, this is not the case for all possible keys, so I needed to find a more general algorithm.
Tags