List comprehensions provide you with a “concise way to create lists”, according to the official docs, but they do a lot more than that. They’re a great feature of Python; let’s do a few examples to illustrate why. List comprehension as a map function The example above is the same as using a map function […]
Archives for February 2023
Git log customization
The git log command outputs a lot of useful information—message, author, date, hash, branch—but its default format leaves something to be desired. Mostly, it just takes up too much screen space. Here’s an example, using the popular Python package flask: The default git log above has all the information we want, but just two commits […]
Copy and paste from the command line
We use copy and paste all the time, so why not use them from the command line? I do it all the time, so let’s do a quick run down. First, the commands: Copy something from the web and paste it to a file This is my most frequent usage of either of these commands, […]
Git commit and commit message best practices
I’ve seen lots of advice about git commits and messages over the years—some good, some not so good. This post will go through what works for me. Note: I’m no git workflow expert, these are just my personal opinions developed over ~10 years working at startups. Commit Best Practices: Commit Message Best Practices: Let’s go […]
Writing CSVs in Python
To write CSVs in Python, you’ll want the builtin csv module. More specifically, I usually use csv.DictWriter. Python DictWriter Python’s csv module has both a writer and a DictWriter class, but I’m virtually always working with dictionaries, so I always use DictWriter. It’s pretty straightforward. You grab your data, open a file in a context […]
Python “is” operator vs double equals “==”
Python’s is operator compares object identity, while == compares object values. Python “is” operator In Python, is compares identity. In other words, it checks if two objects are the same object. It does not care if they have equal values, it cares if they have the same id in memory. This is why you often […]
How to free up disk space
Part of being a developer means constantly downloading new packages, updates, codebases, etc. Eventually, your computer starts to fill up. This post details how to clean it out. The du command This is the disk usage command, and it is key to figuring out what is using your space. Here’s my usual workflow: Starting at […]
Using a custom domain for github pages
Custom domains make your projects feel more legit, and they’re pretty easy to set up. This post will walk you through setting up a custom domain for github pages, but it assumes you have a few things already: With those assumptions in place, let’s set up a custom domain! As an example, here’s a project […]
Find elements in a ruby array
There are several ways to do this, and their outputs differ based on your needs Let’s do a couple of examples. Array.include? Simple: Array.index This method is a bit confusingly named. It gives you the first index at which the given element appears, not the element at the index given. Array.find and Array.detect Two names […]
Insert into javascript array at a specific index
There are two options when inserting into an array in javascript: slice() and splice(). Array.prototype.slice Array.prototype.slice returns a copy of a portion of an array, like so: Let’s say we want to insert c where it belongs in this list, between b and d. The three dots … in the above example are known as javascript spread syntax, […]