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 […]
Archives for January 2023
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 […]
Calculate Date Difference in Javascript
You have two main options: Let’s go through a quick example of each approach. Using date-fns to get date difference Above, I mentioned luxon, day.js, and date-fns. They’re all great packages, but I personally prefer date-fns due to its easily searchable documentation. date-fns has a ton of other functionality and the docs are very good […]
How to find files on linux / mac
Command line find is a powerful, underutilized tool. In this post, I’ll go through the following use cases: Find files by name I use this all the time. Let’s say I’m in my ~/Downloads directory. That directory has several hundred files in it—and quite a few subdirectories—so it’s a bit hard to comb through in […]