Microblog


7/2/2024

Debugging Python in VSCode

# python

They say you learn something new every day, but I was shocked to learn about a fantastic Python feature I had no idea about.

Apparently, you can pause execution of a Python file and open up an interactive terminal with the local variables! I discovered this while watching Andrej Karpathy's video about reproducing GPT-2 (trust Karpathy to know about random tricks like this.)

Just import code at the top of your file, then put code.interact(local=locals()) at any place in your code. Voila! When execution reaches that point, a Python interpreter will open in the terminal with access to all local variables. You can press CTRL+D to close the interpreter and continue execution, or type quit() to quit the terminal and stop execution.


7/2/2024

Making a Radix Dropdown the Same Width as Its Trigger

# tailwind
# nextjs

My website uses the shadcn Dropdown Menu (based on Radix's DropdownMenuPrimitive) to allow users to change the current website theme.

By default, the content of a dropdown component isn't the same width as its trigger. That bugged me, and so I spent a while looking for a solution. Finally, I found the answer in Radix's docs!

Put the below code in your CSS file (you can remove the @layer utilities wrapper if not using Tailwind):

@layer utilities {
  .dropdown-content-width-full {
    width: var(--radix-dropdown-menu-trigger-width);
    max-height: var(--radix-dropdown-menu-content-available-height);
  }
}

Now, change your <DropdownMenuComponent> to look like this:

<DropdownMenuContent align="end" className="dropdown-content-width-full">

Voila! The content and trigger are the same width. You're welcome.


7/1/2024

On Microblogging

# writing

I'm a deep believer in the power of writing as a tool for thought. I often find that I don't truly understand a concept until after I've written a thorough explanation. Writing also helps me remember ideas better and apply them into my life more effectively.

I'm also a deep believer in the power of sharing knowledge. As a computer programmer, I want to share bug fixes and hacks I've discovered. As a mathematician, I want to share interesting insights about new concepts I've learned. As a language learner, I want to tell others about fascinating historical details or words in various languages. And as a human, I want to connect with other people and have the opportunity to be heard.

Despite the importance of writing, I'm quite busy. I don't have time to write a polished blog post about every topic I want to share. Nor do I care to refine my writing extensively for public consumption.

Thus, I'm starting a microblog. Here I'll write about any topic that interests me — math, computer science, faith, philosophy, languages, etc. I may also share external links, book reviews, or interesting personal experiences. My tone will range from formal to casual as I please.

Speaking of tone, I'm placing one constraint on my microblog: I won't allow myself to use LLMs in authoring posts. This should force me to maintain my writing skills, provide me with an archive of content that is mine alone, and reflect my personality more genuinely.

I hope you enjoy reading! If you're an RSS user, you can subscribe at /rss.xml?type=microblog.