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 […]
Latest
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, […]
Calculate Date Difference in Python
Getting the difference between two dates or datetime objects in python is delightfully straightforward; you can just subtract them! For date objects The subtraction returns an object of class timedelta, which has a few handy properties like .seconds and .days. If using whole date objects however, only the .days property will matter. Since there’s no […]
Git commit amend
Maybe there’s a typo in your most recent commit message, or maybe you forgot to add a file. Git commit –amend allows you to go back and modify your commit—no one has to know you made a mistake. Amend a previous commit message Here’s a quick example fixing a typo in a message: Amend the […]
Check if a key exists in a Golang map
Use an “index expression“. Buried in that official doc link is an example like this: In other languages, using index expressions (a term I just learned) could be risky if the key doesn’t exist: Instead of blowing up, or returning a generic (and possibly dangerous) value, Go gives back a second piece of information letting […]
Command line manual pages and tldr
When looking into command line … commands, you’ve probably seen the man command, which is short for manual. For instance, if I want to know all about the ls command I can run man ls, which returns this on my mac: That’s a lot of info, and the screenshot above just the tip of the […]