Hi, I’m Sam

This is my blog. I also have a website thing.

Debugging JSON Data in LLDB

Posted on

Recently, I added a snippet to my ~/.lldbinit for an easy way to print JSON in LLDB. It has saved me a ton of time, so I thought it was worth explaining.

Here’s the snippet:

command regex json 's/(.+)/expr let input = %1; print(String(data: try! JSONSerialization.data(withJSONObject: (input is String ? try! JSONSerialization.jsonObject(with: (input as! String).data(using: .utf8)!, options: []) : (input is Data ? (try! JSONSerialization.jsonObject(with: input as! Data, options: [])) : input as! Any)), options: [.prettyPrinted]), encoding: .utf8)!)/'

Continue reading →

Thirty-One

Posted on

Today, I’m 31 years old. Crazy.

That seems like such an old age. I remember thinking when I was 22 that I better get everything done by the time I’m 30 since my career or whatever will be over then. Hah, such a kid.

Last year, I wrote this:

Continue reading →

Home Assistant, Sonos, and Siri

Posted on

Lately, I’ve really been getting into Home Assistant. It’s a really fantastic way to connect everything in your house into one place and then control it however you want. I connect everything directly to Home Assistant and then add Home Assistant to HomeKit (Apple’s Home app). So HomeKit is just controlling Home Assistant which is controlling the real devices.

I plan to do a getting started with Home Assistant post at some point. For now, I just want to go over controlling Sonos with Siri. (I specifically want to play Apple Music on Sonos via Siri. Apparently you can do this with Alexa, but I want to use Siri.)

The key to using Siri to control things in Home Assistant that aren’t supported in HomeKit is the Shortcuts app. Since things you add here are accessible from Siri, you can create shortcuts for things you want to do and then ask Siri to do them for you.

Continue reading →

Quickly Opening Projects in Xcode

Posted on

I’ve used a little utility called x for several years now. Simply running x in a directory will open the directory in Xcode. Here’s an example:

Now the project is open in Xcode. So quick!

I just extended it to support Swift packages that don’t have a project since that works so well now.

Continue reading →

Diving in Cozumel

Posted on

Last week, I went diving in Cozumel, Mexico. Cozumel is a small island off the coast of Cancun. This is the fourth year I’ve gone diving here. It’s one of my favorite places to dive because it’s relatively easy to travel to (versus something like Little Cayman) and has incredible wildlife. The water was 87°F with ~60ft of visibility. Incredible.

I think I’m starting to figure out my underwater camera setup. I’m really pleased with some of these photos. You’re probably here for the photos, so let’s get straight to that. More about the gear at the bottom of the post.

Update: My dive buddy, Chris Sohl, shot a really great video of the trip. I’m the one with the big camera.

Continue reading →