KISS

Keep It Simple Stupid

OSX says, “iCloud Drive may not work properly”. I say, “Who cares?”

| comments

I had to upgrade recently from OSX 10.11.6 to OSX 10.13.3 to be able to run the latest Xcode. The upgrade has broken a few things and also brought a bunch of new system stuff — I found out about a dozen of new daemons because my Little Snitch was popping an alert quite often after the upgrade.

There were some questionable daemons trying to access the internets, for example keyboardservicesd — based on the name only, why would a keyboard-related daemon connect online? I didn’t want to get into the details so I just blocked almost all of them. But why stop at blocking the access? A better way is to actually stop these muddy services, that’s what I did and ended up seeing this “iCloud Drive may not work properly. Please check the iCloud preference pane.” alert every time I opened the Open/Save File dialog in any application — it showed up once per app launch.

"iCloud Drive may not work properly. Please check the iCloud preference pane."

That is very annoying, especially since I don’t care about this iCloud thing at all and I would gladly remove/disable it altogether in an official way, but guess what, Apple doesn’t provide that way (at least, I couldn’t find anything online). I was then searching for this message to figure out what is possible to do to get rid of it — nope, nothing. I had to brush up on my little reverse engineering skills to deal with it myself. The step-by-step story (and guide to repeat it) is below.

IPA export error in Xcode and ruby

| comments

I needed to archive my project and export its .ipa file with Xcode, so I went to “Product” > “Archive”. After building the project a new window opens where you click “Export…”, then select “Development”. And it shows “The data couldn’t be read because it isn’t in the correct format.” error:

"The data couldn’t be read because it isn’t in the correct format." Xcode error

How can it be an incorrect format?! Xcode restarts didn’t help.

OSX: `sudo` with insults

| comments

I’ve had this line in my /etc/sudoers file for years:

1
Defaults insults

It enables the insults option, which prints a funny message instead of boring “Sorry, try again” when you type an incorrect password for sudo. The man page says:

If set, sudo will insult users when they enter an incorrect password. This flag is off by default.

I noticed that it stopped working quite a while ago — I don’t remember seeing the insults in OSX 10.11.6, nor now in 10.13.3.

swift: Functions are more generic `enum`s

| comments

Let’s say you have a structure with two very similar properties and you need to choose one of the two. You don’t know which one at compile time, so you need to have a parameter to change that at runtime. This post shows this in a very simple and contrived example, given the data structures:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct Person {
    let firstName: String
    let lastName: String
    let age: UInt8
}

struct PersonId {
    let name: String
    let age: UInt8
}

let johnDoe = Person(firstName: "John", lastName: "Doe", age: 42)
print("Input: \(johnDoe)")

// Input: Person(firstName: "John", lastName: "Doe", age: 42)

The Person (the input) has two names: firstName and lastName, and when you need to convert it to a PersonId (the output) you need to select one of the names. How do you do that?

An infinite list usage example in swift

| comments

Learning various programming paradigms is very useful to extend your mind and also design approaches in your main language. For example, this post describes a simple example where infinite lists, as in Haskell, allow us to solve a problem in swift more elegantly.

The simple task

Let’s say we have some basic data structure in our domain model:

1
2
3
4
5
6
7
8
9
10
11
public typealias Label = String

public struct ColoredLabel {
    public let label: Label
    public let color: UIColor

    public init(label: Label, color: UIColor) {
        self.label = label
        self.color = color
    }
}

We have a list of Labels, which can be of any length, and we need to add a color to every Label, create a new ColoredLabel and send it to another system. We have a predefined set of colors, let’s say only three of them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public let labels: [Label] = ["a", "b", "c", "d", "e", "f", "g"]

public let defaultColors: [UIColor] = [.blue, .green, .orange]

public extension UIColor {
    open override var debugDescription: String {
        switch self {
        case UIColor.blue: return "blue"
        case UIColor.green: return "green"
        case UIColor.orange: return "orange"
        case UIColor.black: return "black"
        default: return super.description
        }
    }
}

I’ve also overridden the debugDescription for our set of colors to make the debug output below more readable.

How do you color each label in case when we have more labels than colors, given that the colors should be looped?

How I manually “reassociated” not quite deleted Time Machine backups

| comments

The problem statement

It all started with the need to reinstall my OSX. I have Time Machine backups, so I planned on making the final one before update, but there is no way to actually lock it. So a good idea is to make an image of your drive with another tool. I needed to clean the old TM backups first, so I ran:

1
2
3
4
5
6
7
# get the earliest ones
$ tmutil listbackups | head -10
2016-10-01-000000

# remove them
$ tmutil listbackups | xargs sudo tmutil delete

…and I missed the | head part there, which meant it’d remove all the backups. Since it’s very slow at removing them (not just rm -rf), I stopped the process at the first backup, so the rest was still there, but tmutil listbackups displayed an empty list from then on. I tried remounting the drive, running tmutil inheritbackup, tmutil associatedisk, disabling and reenabling the backup destination, selecting the backup directory by Option-clicking the TM icon — nothing worked to repopulate the list, only the new backups were visible. The official Time Machine UI displayed the same situation.

“code signing blocked mmap()” on iOS Device

| comments

One of my colleagues got a strange error when trying to run our iOS application on an iPad:

1
2
3
4
5
dyld: Library not loaded: @rpath/CocoaLumberjack.framework/CocoaLumberjack
  Referenced from: /var/containers/Bundle/Application/UUID/Incredible.app/Incredible
  Reason: no suitable image found.  Did find:
  /private/var/containers/Bundle/Application/UUID/Incredible.app/Frameworks/CocoaLumberjack.framework/CocoaLumberjack: code signing blocked mmap() of '/private/var/containers/Bundle/Application/UUID/Incredible.app/Frameworks/CocoaLumberjack.framework/CocoaLumberjack'

vim everywhere (almost)

| comments

I’ve been using vim occasionally for over six years now, and more and more recently. Basically, any text editing in the terminal is in vim, so I got used to the convenience of using shortcuts to navigate and edit files quickly. And there are vim modes available in other apps as well. This short post is about those that I use (almost) every day:

Faster DNS on OS X

| comments

There is one operation that’s completed very often when programs connect to servers on the internet — that’s resolving DNS names (finding out the server’s IP address by its name). Typically, you use a DNS server of your ISP. It’s relatively close to your network, so it may be fast. This short post is about setting up a local caching DNS server on OS X for even faster DNS responses.

Persistent application container directories in iOS Simulator

| comments

An annoying thing that was introduced a few releases ago in the iOS Simulator is that your apps’ bundle and container directories change their names (a random UUID) every time you run them in Xcode. It makes it very annoying to test your app if you need to check the output files regularly or restore the app’s container to a known state before launching. I’ve found a relatively painless workaround though!