Matthew Lindfield Seager

Finished reading: Rhythm of War Part Two by Brandon Sanderson 📚

Finished reading: Rhythm of War Part One by Brandon Sanderson 📚

Caught the moon and a star smiling and winking at me last night 😉

Adding a banner to staging site using JavaScript

I wanted to put a banner on the test/staging copy of our library management system to make it easier for the librarian to know which system he is using.

Here’s how I added a red ribbon to the top corner, an idea I stole from RailsGuides, using JavaScript:

var div = document.createElement("div"); = "fixed"; = "0"; = "0"; = "100"; = "white"; = "30px"; = "rotate(45deg) translate(27.5%, -40%)"; = "200px"; = "bold"; = "italic"; = "0px 2px 2px 1px #1209096e"; = "2px 2px 4px #5400007d"; = "radial-gradient(circle, rgb(255, 10, 0) 0%, rgb(200, 0, 0) 90%)"; = "center";
div.innerHTML = "TEST";

Finished reading: Dawnshard by Brandon Sanderson 📚

Finished reading: Oathbringer Part Two by Brandon Sanderson 📚

Today I learned that Cloudflare has a free alternative to ngrok, Cloudflare Tunnel

Can use it without logging in on their domain or set it up with named destinations at own domain

Just finished Oathbringer Part One by Brandon Sanderson 📚 Might have to wait a few weeks until holidays to read part two… and the rest of the series.

Finished reading Edgedancer by Brandon Sanderson 📚

Icon Set from a single image in 15 seconds

I built some AppleScript applets to launch Gmail to a specific account and Brave to a specific Profile (could also be done with Chrome) but I didn’t like the generic “Script” icon.

Screenshot of dock icons showing the ugly default script icon between two snazzy custom icons

At first I just pasted my custom image into the “Get Info” window to update the icon but then when I made changes to the app and re-saved it, the icon got reset. I wanted to permanently updated the “applet.icns” file in the bundle but I didn’t want to spend an hour fiddling around with all the icon sizes.

Turns out, creating an icon set is super easy once you have your starting image:

  1. Copy your image
  2. Paste it onto the icon in the Get Info window
  3. Copy the new icon from the Get Info window
  4. “New from clipboard” in Preview (or just ⌘ N)
  5. Save…
  6. Option click the Format dropdown and choose ICNS
  7. Save

You now have an ICNS file with all 10 variations in it:
Screenshot showing 10 different icons

Step 2:
Paste your image onto the icon in the Get Info window

Step 3:
Copy the new icon set from the icon in the Get Info window

Step 6:
Option click the Format dropdown to expand the available types and choose ICNS

So happy to solve a longstanding performance bug! 🎉

I finally solved a hugely annoying performance bug in one of my Rails apps! To give you an idea of how bad it had gotten, just before the fix an admin page I use 5-10 times every Saturday was averaging 21,114.2 milliseconds per load!!! 😱 Although really, when the times are that large, milliseconds is probably the wrong unit of measurement… That page was taking 0.00024 days to load!!! And the trend was only getting worse!

That same page is now averaging 22.4 milliseconds, about 3 orders of magnitude quicker!

I’d been trying to figure it out for months but I was hampered by a combined lack of:

  • motivation; public facing pages were “only” taking 2-4 seconds and no one had complained
  • expertise; I’ve never had to solve performance problems on my own before
  • tooling; I had inexplicable issues getting Rack Mini Profiler flamegraphs to work on the site, in development or on production 🤷‍♂️

The tooling problems were particularly frustrating so I owe a massive thank you to Nate Berkopec from Speedshop who not only puts out a ton of great content but was also very patient with my beginner questions about why my flamegraphs weren’t working. I didn’t end up figuring out that problem, but at Nate’s suggestion I switched to rbspy to create a flamegraph and within about an hour I’d figured out the problem that I’d previously spent months off and on trying to solve.

It turns out that every time I fetched a person from the database, my app was generating a random password for them. That process is a bit slow (possibly by design? to avoid timing attacks?? maybe???). Individually, 200 milliseconds to generate a password isn’t a big deal… but on the admin page I load a list of all the people, so every time a new person got added, the page slowed down by another 1/5 of a second 🤦‍♂️

In the end the fix was super simple, I now only generate the random password (and other default values) if the person isn’t already in the database:

# Before
after_initialize :set_default_values

# After
after_initialize :set_default_values, if: :new_record?

18 more characters to remove a 94,160% slow down! Plus now the user facing pages are down below 30 milliseconds too! 🥳

For future reference, here’s how I tracked down the issue:

  • Installed rbspy using homebrew
  • Obtained my web server process’ PID from tmp/pids/server/pid
  • Captured a trace on my Mac using sudo --preserve-env rbspy record --pid 86229 --format speedscope --subprocesses
  • [Not tested but could maybe combine the above two steps with something like sudo --preserve-env rbspy record --pid `cat tmp/pids/server/pid` --format speedscope --subprocesses]
  • Request the offending page or pages then go back and end the rbspy recording with control-c
  • Drag the resulting speedscope file from ~/Library/Caches/rbspy into speedscope
  • Found the offending call at the very bottom of the flamegraph “stalactites”

This will be my last M.b post cross-posted to Twitter.

You can find everything I write at (also available via RSS) and for those on Mastodon, is already compatible:

Finished reading Words of Radiance by Brandon Sanderson 📚

Over 1,000 dense pages but I thoroughly enjoyed it. Looking forward to the rest of the series arriving in country next month.

Files App on iOS/iPadOS is not limited by Screen Time restrictions or Downtime

After doing some research today it seems there is no way to block the Files app using Apple’s Screen Time settings. Even when the entire device is locked at Downtime, there is no way to block the Files app. Chlidren can therefore use the Files app at any time of the day or night to:

  • Listen to audio files
  • View images
  • Read PDFs and text files
  • View Excel, PowerPoint and Word files
  • Preview contents of Zip files

I suspect this also means that time in the Files app isn’t tracked as part of the Screen Time time limits.

Some restrictions still apply despite this fairly large loophole:

  • Videos can’t be watched; “You’ve reached your limit on Entertainment” (even if you try and cheat by choosing the “Trim” option to edit rather than view or if you put it in a Zip file and preview the contents of the Zip 👍)
  • iWork files can’t be previewed unless their corresponding app is Always Allowed; “You’ve reached your limit on Keynote”
  • Anything that can’t be “Quick Looked” (previewed) in Files can’t be viewed (ePubs, Google Sheets/Slides/Docs/Sites, etc)

This seems like a pretty big gap in Screen Time to me. If you care about this and happen to know anyone at Apple you can prod, I’ve filed Feedback 11953747.

Finished reading: The Way of Kings Part Two by Brandon Sanderson 📚

Finished reading: The Way of Kings Part One by Brandon Sanderson 📚

In the nick of time before semester 2 starts tomorrow, I just finished The Lost Metal by Brandon Sanderson 📚

Finished reading: The Bands of Mourning by Brandon Sanderson 📚

Finished reading: Shadows of Self by Brandon Sanderson 📚

Finished reading: The Alloy of Law by Brandon Sanderson 📚

Finished reading: Mistborn, The Well of Ascension and The Hero of Ages by Brandon Sanderson 📚

PSA for macOS Terminal users:

Terminal Prefs → Profiles → Shell:

  • Ask before closing
  • Close if the shell exited cleanly

No more accidentally killing your local dev server with ⌘Q. To close a terminal tab/window without confirmation close the shell with ^D

Thinking about ways to disambiguate the same username on different federated instances based on a question from @manton

Pic shows the same username on and Avatar colour would be dynamic but always the same for the same service…

Installing Teams for an upcoming meeting and noticed the installer is called “Teamsosx”. OS X was renamed macOS in 2016, almost a year before Teams was released. It’s inattention to details like this that make Microsoft products really stand out 😉

Trying to stay positive online so rather than bash Hover I’ll compliment Cloudflare. Cloudflare domain registration is:

  • 47% cheaper
  • Just as private
  • More transparent
  • More convenient (since my DNS is already hosted there)

80% of my domains now transferred 😉