A CLI icon with the word 'vipe' to the right. There's some blurry text in the background that looks like a command.

Vim + pipe?

Every now and then you come across a little tool that makes you go “Oooh, that’s neat. Wish I’d known about that before.vipe is one of those. Granted, you might not need it every day, but sometimes it’s just the right tool for the job.

The tl;dr: is that it’s a way for you to pipe something into your $EDITOR and then pipe it on into another command when you’re done editing it. That’s right! There’s no need to save it to an intermediate file and clutter your workspace, nor do you have to do everything via sed (though that can be a fun experience).

How did this come about? Well, we wanted to migrate a config map from one OpenShift project to another at work. Rather than saving the config to an intermediate file, we wanted to see if we could pipe it through an editor and back into oc apply with the required changes. And sure enough, we could:

The first command gets the config map from the server in yaml format, the second (vipe!) pipes it into your $EDITOR, letting you make any necessary changes, and the last one takes your updated config map, applying it to the server for you.

vipe is available as part of the moreutils package, available via various package managers including Apt, Nix, and Homebrew. There’s a couple more interesting packages in there too, so it’s worth checking it out just for that!


On differentiation

The muddy parts

Let’s talk math. Specifically, calculating derivatives through differentiation. I’ve been taking a calculus course at my local university lately, and one of the things that’s come up and bit me a couple times is how a lot of the reference material we’re given for differentiation shows off differentiation in a way that isn’t entirely clear. So in this post I want to record for the future me just how differentiation works.

Implicit derivatives

When the common derivatives are listed, they’re listed for the variable x, and the fact that you’ll need to apply the chain rule ((f ∘ g)′ = (f′ ∘ g)g or (f(g(x)))′ = f′(g(x)g′(x)) when working with expressions is not really made clear. For instance, let’s look at the derivative for natural logarithms:
$$ (\ln |x|)' = \frac{1}{x} $$

This works great for a single variable x, because the derivative of x is 1. However, in cases where x is an expression (2x, x2, sin x, …), you’ll need to multiply that fraction with the derivative of the expression x. For this reason, I think it’d be much clearer if the formula sheet had it listed like this:
$$ (ln |x|)' = \frac{x'}{x} $$

Similarly, this also goes for other derivatives, like sines, cosines, powers of e, and so on:


$$(\arcsin x)' = \frac{x'}{\sqrt{1 - x^2}}$$


Add updated files only

The secret option to save you some face
The git logo with the title of the article superimposed next to it.

Keep those untracked files out!

Sometimes you’re just a hair too quick when working with git, run a little git add -A or git add ., and then let an unwanted file or two come along for the ride. Regardless of whether it’s just random scribbles or actual secrets, it’s pretty annoying. And if no-one notices before you push it to the remote (or open a merge request), it could be a good few levels worse. Today I learned a way to avoid this, and I want to share it with you, dear reader.

Now, just to be clear: I don’t actually recommend you blindly add all files in a directory or project to git. It’s usually better to be explicit about what you’re adding. Sometimes, though, it’s just easier to add everything. Claiming that I’ve never done it or that it’s never caused me grief would be disingenuous at best.

So what’s the solution you ask? It’s a simple flag you can pass to git add: -u or --update. Much like the flag name would suggest, this makes it add only updated files.

The docs say that this option will “update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files”. So you can point it to a directory and it will add all changed or deleted files in that directory, but no new files.

You can also use it without a path, which will just add all deleted and modified files: “If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated”.

So next time you want to blindly add all your changes (but no new files!) to git:

Psst! Here’s a little bonus resource for ya: For more information on the behavior of git add with different options, check the answers to this stack overflow question, which is what put me on the trail of git add -u in the first place.

First Prev Page 2 Next Last