Software Engineering in Web Development, Backend Services, and More

Category: Notes (Page 1 of 50)

Notes on programming-related problems that I’ve encountered while working on various projects.

How To Back Up Claude Settings With rclone

Lately, I’ve been using Claude pretty heavily more than other LLMs. Over time, I’ve accumulated settings, plugins, and various configurations that I don’t want to lose. If I ever set up a new machine, I want to be able to restore those settings without rebuilding everything from scratch.

So I set up a backup system using rclone and Google Drive (though you can use any cloud provider of your choice with rclone).


Continue reading

Thanksgiving 2025

Last year, I wrote:

At this point, it’s more of a tradition to post on Thanksgiving Day than anything else. 

And I still hold that to be the case.

This year, I’d be remiss if I didn’t say something about looking forward to Stranger Things given that it’s been such a major show for the past nine(!) years and the first volume of the final began this weekend.

If you’re in the United States (or if you’re American and celebrating else where), I hope the day is great.

Next month, I look forward to doing another post on a retrospective of the year.

Thanksgiving 2024

At this point, it’s more of a tradition to post on Thanksgiving Day than anything else. I’ve been doing it for 12 years now.

Happy Thanksgiving

But the general sentiment is still the same as it was 10 years ago:

We’re celebrating Thanksgiving today in the United States, so I’m taking a day off of the typical routine.

If you’re in the United States and/or are celebrating today, may it be a good one. And if not, may your day still be just as great.

I’m looking forward to ending the year strong and with a few more posts as I try to get back in the habit.

Thanksgiving 2023

For nearly every year I’ve written, I’ve made sure to publish a post on the end-of-the-year holidays here in the United States.

Happy Thanksgiving!
This is the earliest Thanksgiving photo I have in my library.

It’s neat to see what I wrote on this day 10 years ago in comparison to now:

For those of you who are in the United States and are celebrating Thanksgiving, I hope you guys have an awesome day hanging out with your family, friends, eating, sleeping, and generally enjoying the day off.

A lot has changed both personally and professionally since then (though I’m still working in the same industry and enjoying it as much as I always have), but the message is consistent: If you’re in the US, I hope you enjoy the time off; if you’re elsewhere, I hope you enjoy whatever you’re doing today, too.

Block Notes: Generate a Reference to a Block

I’m working on a block that, like many, isn’t limited to a single instance in the editor (and thus not the frontend); however, because there are certain features of the block I want to manipulate when the page loads, I want generate a reference to said block.

For example, the structure of the markup in the edit function looks something like this:

<div className="wp-acme-block">
  <div className="wp-acme-block-editor">
  </div>
  <div className="wp-acme-block-preview">
  </div>
</div>

The functionality will allow the user to toggle the visibility of the editor container and the preview container. And to manage this functionality, I want to access the parent element of each one. Specifically, the one with the class wp-acme-block.


And this is easy to do with a couple of features of React:

  • useRef is a hook that allows for direct interaction with the DOM. It returns a ref object that maintains a property called current. This enables us to maintain a reference to a specific element.
  • useEffect is a hook that handles side effects in functional components. It allows us to do a lot of things (like fetching data) but also allows us to manually work with the DOM.

Given those two hooks, I can place a ref attribute on the primary container that I can then use elsewhere in the code.

First, in the header of the file add the following:

import { useRef, useEffect } from 'react';

Then at the top of the edit function, I have the following code:

edit: ({ attributes, setAttributes }) => {
    const blockRef = useRef(null);
    // ...
};

Then, in the edit function where I have the markup that I’ve shown above, I’ll add the ref attribute:

<div className="wp-acme-block" ref={blockRef}>
  <div className="wp-acme-block-editor">
  </div>
  <div className="wp-acme-block-preview">
  </div>
</div>

And finally, I can use this reference in the edit function before it calls return so I can refer to the element in other functions.

useEffect(() => {
  acmePreviewFunction(blockRef.current);
}, []);

So the full, relevant code looks like this:

import { useRef, useEffect } from 'react';

// ...

registerBlockType('acme/example-block', {
  // ...

  attributes: {
    // ...
  },
  edit: ({ attributes, setAttributes }) => {
    const blockRef = useRef(null);

    // ...

    useEffect(() => {
      acmePreviewFunction(blockRef.current);
    }, []);

    // ...

    return (
      <div className="wp-acme-block" ref={blockRef}>
        <div className="wp-acme-block-editor">
        </div>
        <div className="wp-acme-block-preview">
        </div>
      </div>
    );
  },
  // ...
});

Then passing the current property as an argument to other functions, you’ve got access to the block such that you can manipulate it with other JavaScript functions.

Further, the ref will refer only to the instance of the block so it won’t manipulate other instances of the block located in the editor (or, more specifically, the DOM).

« Older posts

© 2026 Tom McFarlin

Theme by Anders NorenUp ↑