Go has a few for loop options: Classic for loop This format is common in many languages: The one difference in Go is the lack of opening parentheses around the init statements, which are required in other languages like Javascript, Java, or C. For loop using range Golang doesn’t have a for in loop, but […]
Bash ampersand (&)
The single ampersand & is used to run commands asynchronously in the background. From the bash docs: If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell. This is known as executing the command in the background, and these are referred to as asynchronous commands. The […]
Python double slash operator
Python’s double slash (//) operator performs floor division. What exactly is floor division? Floor division is a normal division operation except that it returns the largest possible integer. This integer is either less than or equal to the normal division result. – Educative.io In code, it looks like this: Some languages perform floor division by […]
Is Comcast throttling me? The technical details
In case you aren’t one of the three people in the world who read the first post in this series, Is Comcast throttling me?, let me bring you up to speed: This post is about how I reached the conclusion in #5 from a technical standpoint, including code snippets. If you just want the results, […]
How to kill a process
The easiest way: use pkill to kill a running process by name. Let’s say you have a background task running: Those sleep commands will run for 60 seconds and 600 seconds, respectively. Kill a process by name If we want to kill them sooner, we can just pkill them by name: pkill works similar to […]
Golang Ellipsis
Golang’s ellipsis-…-has a few different uses. Defining variadic function parameters What is variadic? It is a function “of unknown arity”. In plain English, that means “a function that can take an unknown number of arguments”. A commonly-used function with variadic function parameters is Go’s builtin log.Printf. This is its signature: The signature of Printf says […]
Is Comcast throttling me?
Update: The conclusions in this post might be invalid. I’ve left the post unchanged but I added a footnote explaining why. I never thought I’d apologize to Comcast, but … sorry I said–in great detail–that your service is bad. It turns out maybe it isn’t? Ok here’s the original post: Since the pandemic, I’ve been […]
The Bash trap command
Bash’s trap command is used to catch and react to signals sent to your shell. It’s similar to an event listener in the browser, or a pubsub topic subscriber. The typical use case is to run some kind of cleanup command when a process terminates, like this: The command above will run cleanup_job when it […]
Dedupe a list in Vim
Tldr: use :sort u Surprisingly often, I find myself needing to dedupe a list, usually when digging through logs. There are many ways to dedupe a list, but Vim might just be the fastest one. Take this list of UUIDs I pulled when investigating a recent issue: From a quick look, I can see that […]
Ruby’s safe navigation operator (&.)
Ruby’s safe navigation operator (&.) is a nil-safe way to chain operations. Let’s say we have a User class, and that class can have first_name and last_name attributes: Without safe navigation, we’d need a more-verbose if check to accomplish the same thing: If you’re familiar with Javascript, ruby’s safe navigation works just like javascript’s optional […]