Ruby (and Rails) have many ways to test whether something is … present. But each method behaves slightly differently, and some are Ruby-native while some are added by Rails. Here’s the summary, in case you don’t feel like reading the full details below: .nil? (Ruby) .empty? (Ruby) .blank? (Rails) .present? (Rails) true false NoMethodError […]
Latest
JSON in Python
Working with JSON in Python relies on Python’s builtin json module. After you import json, here are the json module methods: Notice that the methods ending in “s” deal directly with strings, whereas the others deal with files. To disambiguate them, I call them “load string” and “dump string” (in my own head, at least). […]
Python sets
Sets are one of Python’s built-in types, and they’re very useful for deduplicating and comparing collections of data. Sets have tons of useful built-in functionality, and this post covers a lot. Here are some jump links to make life easier: Creating a set There are a few options: Check if a set contains a member […]
Countries of the world
During the 2020 Olympics, I was curious about the competitors’ countries. Sure, I could google each one and load up its wikipedia page, but that’s a lot of information and the wikipedia sidebar isn’t the easiest thing to parse at a glance. So, I created my own small web app to summarize countries for me […]
Git tips and tricks
Git is an essential development tool, and an endless stream of things to learn. This post is some of the tips, tricks, and configurations I use to make life easier day-to-day. Here’s what’s below: Disclaimer: I’m not a git expert. These are just things that have come in handy in my years as a heavy […]
Git Stash
Git stash is for stashing away changes you need but aren’t quite ready to commit. The command saves your local modifications away and reverts the working directory to match the HEAD commit. – Git Docs There are a few important stash-related commands. Git stash Say you’re on the main branch, and you started making edits […]
Git Diff
When you want to compare two branches, use git diff. I usually like to pair it with the –stat option for a quick visual summary. Git diff branch_name.. Let’s say I’m on a test branch, and I want to see how that branch differs from main. I can get a quick overview via git diff […]
Developer workflow tips no one tells you about
As developers, we’re expected to know a lot of random things. Sure, you can learn data structures and algorithms from a CS class, and you can learn frameworks from online tutorials or a bootcamp, but what about the other things? How to be more effective on the command line? How to increase productivity on your […]
Flatten an array in Javascript
Flattening an array means making it one-dimensional. The easiest way to flatten an array is via Array.prototype.flat. For many years, doing this in javascript required the use of concat, spread, or reduce. Not anymore. Flatten with Array.prototype.flat This method does exactly what you’d expect: By default, flat only flattens one level deep: But flat accepts […]
Python try except
Try and except are the building blocks of exception handling in Python. You’ll also sometimes see finally and else. Here’s the summary: Try and Except A simple try-except block looks like this: You’ll usually see try and except by themselves; finally is used less often, and else even less. Here’s a (slightly) more realistic example: […]