Keep It Simple Stupid

A hack to compare doubles without epsilon in swift

| comments

Some time ago I worked on a proof-of-concept which used a type-safe units conversion library in swift (that had been before Foundation introduced their own units support). The library had measurements composed of a Double amount and a unit, e.g. “1.5 meters”. To compare measurements in tests with XCTAssertEqual, it’s necessary to conform to Equatable and implement the == function. But how do you specify the accuracy to compare doubles in this case?

Warning: this is a quick and dirty hack that shouldn’t really be used in production. Try to come up with a better design for your code to avoid it if possible.

Upgrading Xcode and XVim

| comments

This is more of a note to self about upgrading Xcode and XVim. XVim2 is a “Vim plugin for Xcode”. A few years ago, Apple released an Xcode Extensions API and broke a lot of third-party plugins by code-signing Xcode and not allowing plugins by plugins. As far as I know, creating a vim plugin using that API is currently impossible, because it’s very limited, so we continue using XVim2. Or you could use the much nicer AppCode with the official IdeaVim plugin if the IDE works with your project (it’s gotten much better last year).

So when I upgraded to Xcode 11.3.1, here’s what I did.

Can’t create a constraint to the superview in Xcode 11’s IB

| comments

After an upgrade to the latest Xcode 11.3.1, I stumbled upon a problem in the Interface Builder. Specifically, I opened an old XIB file to replace a now deprecated UIWebView with a WKWebView, added it and wanted to recreate the constraints of the old web view, most of which were relative to the superview, but failed. I tried Ctrl-dragging from the new web view to the parent view in the visual editor or to the View item in the left sidebar, but it was not selectable; the buttons at the bottom didn’t offer that option either. I’ve never had this problem in earlier Xcodes.

Checking if sudo has insults

| comments

Almost two years ago I discovered that the OSX’s sudo binary doesn’t display the “insults” (see man sudoers) and wrote a post on how to fix that. Today I’d like to append that information with a helpful shell function to check if your current sudo has insults or the latest update has reverted the patched version again (of course, it did).

Three small, fun online games for programmers

| comments

These are three websites hosting cool, fun games/challenges for programmers and maybe other IT people. I discovered them over the past year and want to share them:

  • — I really like this one because it tests your attention to details while you’re trying to figure out which of the two screenshots is more correct. I got most of the answers correct last time I played, with maybe six wrong answers.

  • — It is a very neat game when you are a thread scheduler and need to break poorly-written concurrent programs by pausing and resuming threads at the right times. It presents an “inside-out” view on the common concurrency/threading issues and some of the synchronizing primitives — I can’t say that you’ll learn everything about them, but the game is fun. And it’s open source:!

  • — This game is shorter than the two above, but it does show some exaggerated examples of the bad user interface, and you need to navigate through them. Unfortunately, these bad UIs are present on real websites too; the most annoying ones for me are uninformative/missing requirements for password fields and bank card input fields that are so dumb that can’t filter out spaces.

Playlist — iterator in the real world

| comments

This is a short post about an observation from the real world about playlists. I use the amazing SanDisk Sansa Clip+ music player with the great, open-source Rockbox firmware to listen to dozens of podcasts. The official firmware has weird quirks about separating music and podcasts, so that you can’t create a playlist of podcast episodes. Rockbox is much better in this. I’ve noticed a very interesting thing after using podcast playlists for some time: they represent the (object-oriented) Iterator design pattern in the real world.

Sequencing multiple SignalProducers

| comments

Let’s say we have a list of usernames and an API that can return the details of a user by her username, and we need to make the requests one after another. We will use ReactiveSwift as a framework to work with asynchronous values. This task involves working with multiple, although the same-typed SignalProducers. The code, step by step, is available at

Note: the code here will be the essence necessary for understanding of the post, without the swift’s boilerplate. The links for the full files are provided.

Bulk removing iOS Simulators

| comments

Xcode is so helpful that it installs the whole bunch of iOS Simulators when you first launch it, even if you already had a previous version of Xcode. The project I’m working on runs only on iPads, so all the other simulators are unnecessary and can be removed to free up some space.

Removing them manually by going to Window > Devices and Simulators (Cmd+Shift+2) is slow and annoying. Even when you’ve selected one, pressed Delete and confirmed the action, the focus in the list will jump to the top, so you then have to first navigate to the previous position.

Here’s a small tip to make this process much faster.

My observations from learning electronics

| comments

I’ve wanted to learn electronics for a long time, and it always seemed a huge field where you’d need to know psychics and differential equations well. Then it started two years ago with the Make: Electronics book and I’ve been learning about this very interesting field of hardware. It is also interesting to note the differences between hardware and software — programming has been my job for eight years. The following is how I understand electronics now and may or may not be entirely correct. I welcome your feedback and clarifications.

Cloning TimeMachine backup drive to another disk

| comments

Updated on 2020-05-10: More “fun” with TimeMachine is here.

Say, you have an external USB drive for TimeMachine backups on OSX. (You make backups, don’t you?) Now you want to replace it with a larger drive, so the task is to copy all the data to the new disk. There are two ways to do it:

  1. Create an equivalent partition setup on the new disk and copy all the files on each filesystem. Since the default TimeMachine setup is to have one (visible) user’s partition, it shouldn’t be too hard, however you want to make sure all the information is copied, including file timestamps, Access Control Lists, extended attributes, etc. The best tool I know for this job is rsync (install a newer version from brew), however I had issues in the past when copying Time Machine backups because those directories have some special permissions and even sudo didn’t help.

  2. Clone the disk byte-by-byte. This is a lower-level approach, which doesn’t care about which partitions and filesystems you have and you will have an exact copy. It will copy all the disk’s bytes, even if you’re really using little space. Since we’re migrating to a larger disk, all the old bytes will fit.

The latter approach seems to me a better one for the exact duplication of a TimeMachine backup drive. How I did it and a few necessary steps follow.