LinkedIn Reddit icon

Dunder Doc

by Valdir Stumm Jr

How Does CPython Multiply Big Numbers?

I am used to write code that multiplies numbers several times a week. Usually when I do that, I don’t think much about the operation itself or how the machine will execute it. But if we start thinking about it, how in hell can the CPython interpreter multiply numbers as large as the ones below? The CPU definitely does not support huge numbers like that out of the box, so how does it work?

How I manage Virtualenvs with Pyenv

I have always been a happy virtualenvwrapper user, but I abandoned it last year to use pyenv and pyenv-virtualenv. I don’t really remember why, as virtualenvwrapper is awesome. The problem is that lately I haven’t been creating and managing a lot of virtualenvs, so I often find myself having to search through pyenv docs to do basic stuff when needed. That’s why I wrote down the usual steps that I follow so that next time I can remember (or find) more easily.

Stop writing for the audience

I’ve been blogging for a long time already, but lately I noticed that it has been becoming harder and harder to finish a blog post. I have an idea, I write a draft, but in many cases the blog post never gets published. I recently realized that the further I get into writing a blog post, the bigger my anxiety on writing something perfect gets. That’s mostly because my mind gets swamped with questions like:

Black formats my code, and maybe it should format yours too

I’ve always been a bit skeptical about code formatters. I don’t know, I always felt like they would curb my freedom to format the code in my own way. Because, you know, no one formats code better than me. 😛 Joking aside, I got to know black about 2 years ago. Everyone was talking about it. A bunch of people adopted it. Massive codebases were being reformatted daily. It was the new kid on the block.

Handling Headers-Based Pagination on APIs with Python

The other day I was building a Python script to fetch some information about all my repositories on GitHub. Their API is pretty straightforward and well documented. Fetching my repos was as simple as: >>> import requests >>> response = requests.get("https://api.github.com/users/stummjr/repos") The thing is that such request gave me a list with all my repos on it. No info on pagination whatsoever on the response body. After a bit of research, I found out that GitHub APIs take advantage of the Link header to expose several pagination options.

CPython Optimizations

CPython is the reference implementation of the Python language. While there are several other implementations, CPython is by far the most popular one. These days, it comes bundled in most of the operating systems. Even though CPython is not the most performatic Python interpreter out there, it does some very interesting optimizations to speed itself and Python programs up. I am pretty curious about things like these and the rationale behind them, even though I know very little about it.

My Favorite IPython Tricks

It’s no secret that IPython is my favorite Python shell. I am the guy who is always asking everyone “did you try IPython already?” as soon as I see they opening the regular Python shell. Yes, I know, you’d probably hate me. The reason I like it so much is that IPython makes it very easy for me to incrementally experiment when coding. I consider experimentation to be a crucial step when writing software, as it helps to reduce the unkowns in a problem or technology.

Tips for boosting your Python scripts

I find myself writing quick command line scripts every so often. They usually automate a random task from my daily routine and end up saving me a bunch of time. These scripts usually start as quick and dirty snippets, but once I figure that they are not a one-off thing, then I iterate to make them more usable. There are several things that I find valuable in scripts like these:

Why I Abandoned Dark Mode

15 years ago, my whole desktop environment was dark. Dark terminal, dark vim, dark graphic environment, and dark mp3 player. It was pretty cool. I felt like a hacker in those unrealistic 90s movies. Whoever stepped into my room would think that I was doing some rocket science. In fact, I was probaby just listening to mp3, learning some bash scripting and taking screenshots to share my cool desktop in online forums.

Writing Scrapy Spiders in 2020

I am a huge fan of Scrapy and I’ve used it extensively for 3+ wonderful years working at Scrapinghub, the company behind this framework. It’s been one and a half year since I used it for the last time, but last week I had to build a spider for a personal project. To my surprise, I am not just rusty but pretty outdated in terms of the new shiny features of Scrapy.