One Month of AirPodsĀ Pro

The initial reviews of the AirPods Pro were incredible, if not a little hard to believe.

https://twitter.com/ryan/status/1189643522418151424

It’s true that the noise cancellation is very good though. I work in cafes regularly and still find it sort of incredible how good they are at cancelling out background noise. If someone is having a loud conversation right next to you, you can kind of hear it if the volume is low enough. The background buzz of people talking is completely gone though.

They also, predictably, stay in my ears much more reliably than the previous AirPods. If you get them, definitely try all the tips. I used the medium ones for two weeks and they were fine, but the smaller ones fit even better.

Transparency mode is the killer feature I feel like nobody is really talking about — it’s audio AR. Paired with a future pair of AR glasses and maybe a watch, you can start to see the path to making smartphones obsolete.

The only (small) problem I have so far is that transparency mode is unusable with any kind of hat that covers your ears, which means I won’t be using it very much for the next few months.

Overall, I find the AirPods Pro very exciting.

josh.blogĀ 2.0

I must have a problem staying away from code for too long. After being on vacation last week, I decided to redo the CSS on this site over the weekend.

The main focus this time was keeping the design as simple as possible and ensuring the text is easy to read. The craziest design element is three little dots that divide articles.

For the colors, I used the Duck Duck Go Color Picker ā€” literally search for “color picker”.

Search & Replace PHP SerializedĀ Strings

Or how we improved the WordPress database migration speed by 40x with Go.

At VIP we move WordPress databases around many times per day and as you can probably imagine, our customers tend to have of a lot of data. When we move data between environments, one of the bottlenecks has historically been search and replace of the domain names. The two main use cases are importing data containing development domain names and moving production data to a hosted development environment.

The best option in most situations is WP-CLIā€™s search-replace command. WP-CLI is fairly ubiquitous at this point and itā€™s easy to use. The problem that we tend to have is that itā€™s not quite fast enough on really huge datasets.

You may be wondering how a simple search and replace could be the bottleneck. WordPress stores lots of PHP serialized strings in the database. Since object lengths are encoded in serialized strings, you canā€™t simply search and replace domain names in the database unless they happen to be the same length.

php > echo serialize( "google.com" );
s:10:"google.com";

WP-CLI deals with this by pulling the objects out of the database, unserialzing them, running recursive search and replace on the resulting object, reserializing them, and then updating the database. While this only takes a few seconds on most WordPress sites, it can take many minutes or even hours on sites with millions of post objects.

Since our migration process is based on .sql files, we thought it might be faster to run the search and replace outside WordPress as long as we could reliably fix the encoded lengths. So, I wrote Automattic/go-search-replace to do that.

There are two main things that happen:

  1. The search and replace. We simply replace one domain with another.
  2. Fix encoded string lengths as necessary.

It turns out that dealing with the string lengths is not as hard as we originally thought. Modifying nested objects is not a concern because we’re not changing the number of nested items. We only need to look at the string length immediately preceding the string we’re replacing.

Another problem that could have been hard to deal with is maintaining the integrity of the .sql file. It would be easy to replace the characters that are used by the MySQL importer to delineate records, like ),\n(. Our solution is to limit the search domain roughly to the characters that make up valid domain names.

Using this new command line tool, we were able to improve the search and replace process by about 25x. I wondered if we could make it even faster using concurrency.

One challenge is that we need to ensure every line in the resulting file is in the same place. For that, we use a buffered channel of channels. For each line, we write a new string channel to the channel and asynchronously write to that channel. Effectively, we put a placeholder on the channel synchronously, and write to it asynchronously. Here’s that code on GitHub.

We’ve been using this in production for over a year now. In some tests we’ve seen the search and replace performance improved by up to 40x. Since we use STDIN and STDOUT, we can use go-search-replace as part of an import pipeline. In some cases, the search and replace runs at line rate and has no effect on the total import time.

Five Tips from Five Years of RemoteĀ Work

I’ve worked from home for a long time now. Forever, really — Automattic was my first real job after college. In a lot of ways, I work similarly to the way I did in college except that I go to a coffee shop instead of a library.

When I started working from home, I noticed people were very concerned that it would be too challenging. I’ve gotten used to the questions, and over the years, I’ve refined my answer to a handful of main points.

  1. Get out of the house most days. Whatever that looks like for you will depend on how you work best and how much you like to interact with other people. It could be going for a walk around the block, spending some time in a coffee shop, or spending the whole day in a co-working space.
  2. Try to follow a routine. Going back to the first point, it helps me to take a walk to a coffee shop every morning. The ten minute walk to the coffee shop is sort of like my commute and defines the start of my day. When you work from home, it’s easy to forget when it’s time to “go home” for the day. Having a routine to start and end the day helps with that.
  3. Take advantage of the flexibility. Like anything, working from home has pros and cons. One of the advantages is the flexibility you get, so use it! I try to get out of the house most days, but I also have the option to stay in if it’s particularly cold or there’s a blizzard and I don’t feel like walking through the snow.
  4. Set up a nice home office. I think a nice chair is a minimum requirement. Don’t cheap out here. It will pay for itself in chiropractor bills. I also like a desk that can convert to a standing desk. There are a lot of fancy automatic options, but I personally recommend saving some money and getting one with a manual crank. I need a nice monitor and noise canceling headphones. Again, do what works for you.
  5. Meet people outside work. Joining a co-working space can be a nice way to do this, but you could join a basketball league or organize a local Internet of Things meetup — whatever interests you. Joining a new company can be a big transition. Especially if you’ve just graduated and many of your friends are moving across the country.

I also like to make a distinction between distributed companies and remote workers. Automattic is a distributed company. Everyone works from home — or wherever they feel most productive. Sometimes people work from home, but in a company where most people are colocated in one or several offices.

The difference might not seem obvious at first, but I think it’s important because it can be a defining factor in how the rest of the company communicates with remote workers. Since we’re all distributed at Automattic, there’s no way to overlook someone who is remote. If most of your company is colocated, it helps to understand how the rest of the company thinks about communication.

Working from home is great. My colleagues sometimes say that they’ve broken me — remote work is all I know. I’m not sure if I could work in an office every day, but maybe someone else can write that blog post. šŸ™ƒ