Showing posts with label Lifehack. Show all posts
Showing posts with label Lifehack. Show all posts

2025-06-17

An orange ring for git submodules

At work we have a common library, call it libThing, that underlies several of the products we produce for one of our big customers. We bring it into the projects that use it with git submodules. And that's a bit of a problem.

Let me explain.

You see, the design of the submodules facility is clearly predicated on an understanding that the submodule is a separate thing, and is not edited in situ by a programmer working on the super-project. If the sub-project needs updating, it is assumed, you will send the maintainer a well defined change request, wait for it to happen, point your super-project at the updated version, and go about your business.

Which is what you would expect if the sub-project belongs to someone else.

And some of our changes look like that: "Folks, we have a note from the customer. There's a new file format for specifying widgets. Someone needs to update the WidgetLoader in libThing to handle it. Joe, you've worked in that module recently, can you get to it this week?". Fine. Joe updates libThing, pushes to the reference repository and the next release of each of our project can manage the new Widget files. Nice. And exactly as Linus envisioned it.

On the other hand a lot of times we find out that libThing needs updates because we're in the course of making changes to one of the project that use it. By working both side together we can work through the trade offs dynamically. Its more natural, and probably faster, to just work on them together. Even though submodules doesn't encourage it.

Buuuut ... if you're not careful, you'll make one or more commits to the sub-project in a detached head state.1

The rest of this post is a recipe getting safely back to a happy state after you make this mistake.

Advancing the branch you aren't on

If you had done this right, you'd have put the subproject on the branch before you started editing and the branch would have advanced as you made commits. We want to get the repository into the state it would have had.

  1. Determine the name of the branch you're suppose to be on by looking in the .gitmodules file of the super-project. Remember that for later.
  2. Give the current state of your work in the submodule a temporary name with git checkout -b life-preserver2
  3. Get on the right branch with a git checkout to the branch you found in step 1.
  4. Fast-forward with git merge life-preserver (and it should be a fast-forward merge; if not you should probably take stock at this point.)
  5. Check that nothing is missing by examining the commit tree. I like gitk --all.
  6. Assuming all is well, dispose of the evidence with git branch --delete life-preserver.
  7. Detach the head again (at least if you're done) git checkout --detach HEAD.
  8. Pretend you're the kind of coder who never misses the little details.

1 If you don't work with git, then this post probably isn't much use to you, but short-short version:

  • In git a "branch" is a name that refers to some remembered state of the project. A project can have a lot of branches, and you can start with one state and make different changes to the project and have both of the remembered as different branches. That is, they can split off like the, well, branches of a tree.* They can also join up which is called a "merge".
  • You can tell git to remember a new state of the project. That's called a making a "commit" and each commit knows about the one(s) it came from, so the software can navigate back in time.
  • A commit can be the target of zero, one, or more branches.
  • You can be "on a branch" meaning that (a) you are working on the state of the project remembered by that branch name and (b) git has a record of which branch you're "on".
  • When you're on a branch and you make a commit, git changes the association of branch name to the new commit. Remember that commits know what came before, so you can still go back, but the name now refers to the new state of the project.
  • If you're not on a branch you are in a "detached head state" which means git knows which version of the project you start with but doesn't know a branch. Any commits you make in this state are nameless because there is no branch name to move forward.
  • * In computerese it's actually a directed acyclic graph (DAG), but that's neither here nor there.

2 Yes, I have a name I use for this. Not that it happens often or anything.

2020-08-01

Squash bugs

My wife and I are gardeners. Not of any particular expertise, but definitely persistent. If I've counted our misses correctly we've been at it seventeen of the last twenty years. At nine sites in five states and six cities.1 I believe we've only failed to garden at all in one of the eight "permanent" residences we've had in that time (a rental we occupied for less than a year).2

We grow flowers and vegatables in containers and in the ground. Roses, irises, marigolds, geraniums and others. Tomatoes, bell peppers, a variety of chilies, egg plant, leeks, beans, peas, assorted squash, selecetd herbs, occasional greens, the odd brasica and others. We use containers in rentals, when space doesn't leave us with a choice, and (in one case) when suspected soil contamination makes us unwilling to eat food grown in the ground.

By my count we've grown squash at seven of the nine sites. And we've had squash bugs in every single one of them. "Loathing" is simply not a strong enough word to describe my feelings about these little creeps.

They showed up here on Wednesday. I found them as the light was fading from the sky, and I spent almost an hour working my way through all our vulnerable plants trying to determine the extent of the infestation and to stop it. Each of the last few days has included an hour or more of fighting them, and we might be winning. It's only cost us one plant so far, which is not bad.

But the vile awfulness of these critters is not the point of this post. Rather it is the "discovery" I made that first evening.

Back-lit squash leaf at dusk

The hard part of hunting squash bugs is that they generally lay their eggs underneath the leaves, and when they hatch the juvenile stages spend most of thier time their as well. It's a lengthy and painstaking process (not to mention tough on the back and neck) to lift each leaf and look underneath. As the light faded, I fired up the light on my phone, and found that I could see my targets through the leaves.

It's much less work and easier on the neck to slip your phone under each leaf.3

In principle, you could have done this with any decent flashlight, but they generally have the wrong form-factor to manuever around the plant: the shape of a phone is much better for the application.


1 Two of those sites were community garden plots maintained in parallel with gardens at our residences.

2 The life of a repeat post-doc is not a stable one. We're good at moving and ready to stop.

3 Sorry, I don't have a photo showing any eggs or nymphs because I don't stop to document my discoveries but move to destroying them at once. It's the only way to be sure. But then, any gardener who's familiar with these things will have no problem spotting the egg arrays and the juvenile stages are pretty obvious as well.

2020-07-23

"Foreign" doctors

Members of my household have accumulated a lot of experience with the US medical industry.1 Just now we have collectively eight specialists across five disciplines (and primary care, of course), and the frequent moves I've subjected my family to have meant finding new people in those (or other) positions repeatedly in the last few decades. We've interviewed many dozens of specialized physicians over the years.2

And I've noticed something about what doctors are available.

Most of the time we get offered appointments in less than a year with two kinds of doctors: people who turn out to be a poor match for us and "foreign" people (meaning people who have a noticeable accent or did part of their training in another country, and often meaning "not white").

Now, to be licensed in this country a doctor needs to do a residency here no matter what credentials they may have elsewhere, so every one of these doctors has been checked out by the local medical establishment (and because we're talking about specialists they have been checked out twice). We've found some of our very best specialists this way. But we've also heard from other members of our communities that they "weren't comfortable" with these same people.

Okay, in one case the physician had a pretty marked accent; one I remember finding pretty hard to process when I first started working with people from the same part of the world.3 I can buy that many residents of that rural and somewhat insular part of America might have found dealing with the accent one problem too many on top of dealing with medical issues. But in most cases these folks have mild accents (presumably owning to spending many years in the States) that merely give their speech an exotic edge.

A strategy

My unscientific conclusion is that some portion of the American public is avoiding a subset of our good doctors for being "not my in-group" (I won't speculate if this is overt racism, implicit racism, or just provincialism) and that means that it's easier for you to get access to those doctors.

The point is that it can be hard to get specialists, especially good specialists, so you don't want to give up any available edge. Don't be put off by an accent or a face of a different shape or color than your own.

Aside on exceptions

We also have very good specialists who are white. And some who are male. And some who are getting on in years. Our current crop includes one who is all three of those things and he's a serious keeper. But we didn't get him by calling the clinic and asking who was available, we asked the specialist at the "from" end of our last more to intervene for us and we got in with this guy on the basis of inter-doctor networking.4 That's been the case with a lot of our specialists who look like they came from central casting.


1 It wouldn't really be right to call it a "system" except in the sense of "ecosystem". There is no organizing principle, and while many parts of it are subject to oversight of one kind or another the oversight level isn't terrible well coordinated.

2 Yes, "interviewed" is the right word. We go into a new specialist's office with the questions "Is this the right doctor?" just as much in mind as the history and needs of the patient. Doctors who want to micromanage a patient used to being part of their own care are a bad match. Doctors who don't want to answer questions when a patient feels they need to know more about 'Why?' are a bad match. Doctors who tell a couple comprised of a graduate engineer and a physics professor "You don't understand the math" actually get laughed at in front of their own staffs (I feel a little sorry about that, but not very; she is, indeed, one of the elite thinkers in our society but dismissing us out of hand was out of line).

3 Much of US graduate education has a lot of diversity in country of origin even when there is not so much in gender, economic background, or race among the Americans. And experimental particle physics is an international endeavor so I got a lot of practice during my years as a scientist.

4 This is another strategy. If you ever have to leave a good specialists (for whatever reason) see if they can hook you up with a replacement. They already know your case and your style and may be able to choose a good match. And their influecne can get you in to see doctors who are "not taking new patients at this time".