Archive for January 13, 2015

Tuesday, January 13, 2015

Dependent Key Paths

Jonathon Mah:

If user defaults can change separately from this code (and you should probably assume it can), providing correct KVO change notifications can be accomplished by having the singleton observe NSUserDefaults with NSKeyValueObservingOptionPrior; posting willChangeValueForKey:@"mySetting" on the prior callback and didChangeValueForKey:@"mySetting" on the post callback. But this sucks — it’s wordy and you pay a (small) performance cost even if mySetting isn’t observed.


It’s valid for dependencies to be specified in either the dispatching or specific methods, all the way up the inheritance chain. Correctly overriding +keyPathsForValuesAffectingValueForKey: requires some tricky code, which I’ve wrapped in a function MLHOverrideKeyPathsForValueAffectingKey in MyLilKeyPathHelpers.

Proof in Functions

Brandon Williams (tweet):

Swift’s generic functions allow us to explore a beautiful idea that straddles the line between mathematics and computer science. If you write down and implement a function using only generic data types, there is a corresponding mathematical theorem that you have proven true. There are a lot of pieces to that statement, but by the end of this short article you will understand what that means, and we will have constructed a computer proof of De Morgan’s law.


The rigorous statement of the relationship we have been grasping at is known as the Curry-Howard correspondence, first observed by the mathematician Haskell Curry in 1934 and later finished by logician William Howard in 1969. It sets up a kind of dictionary mapping terms in the computer science world to terms in the mathematics world.

Update (2015-01-24): [Solutions to Exercises] “Proof in Functions”.

BBEdit Codeless Language Module for .pbxproj Files

Aidan Dysart (via @bbedit_hints):

This is a BBEdit Codeless Language Module for Xcode project files. It provides some amount of syntax highlighting and code folding for project.pbxproj files inside .xcodeproj file bundles. It also works with TextWrangler.

I end up having to directly view and edit these files more than I’d like. The CLM seems to work pretty well.

The Morning Paper

Adrian Colyer’s The Morning Paper highlights “an interesting/influential/important paper from the world of CS every weekday morning” (via Edge Cases).

Functor and Monad in Swift

Javier Soto:

We’ve seen what map can do when implemented on a container type, like Optional, Array or Result. To recap, it allows us to get a new container, where the value(s) wrapped inside are transformed according to a function. So what’s a Functor you may ask? A Functor is any type that implements map. That’s the whole story.


In the earlier example, we used the transformation function to return another value, but what if we wanted to use it to return a new Result object? Put another way, what if the transformation operation that we’re passing to map can fail with an error as well?


And with that, we turned our Result type into a Monad! A Monad is a type of Functor. A type which, along with map, implements a flatMap function (sometimes also known as bind) with a signature similar to the one we’ve seen here.

Old MS-DOS Games

The Internet Archive:

Software for MS-DOS machines that represent entertainment and games. The collection includes action, strategy, adventure and other unique genres of game and entertainment software. Through the use of the EM-DOSBOX in-browser emulator, these programs are bootable and playable.

There is a 1990 version of The Oregon Trail that is text-based and reminds me of the Apple II version. There is also a 1992 version that has Mac-like fonts and widgets.

Why DNS in OS X 10.10 Is Broken

Iljitsch van Beijnum:

For 12 years, the mDNSResponder service managed a surprisingly large part of our Mac’s networking, and it managed this task well. But as of OS X 10.10, the mDNSResponder has been replaced with discoveryd, which does the same thing. Mostly. Here are some strange networking problems we’ve observed since installing 10.10[…]


If discoveryd isn’t doing its job properly, sometimes it helps to restart it. However, even this doesn’t always work, and restarting discoveryd gets old fast. If you’re not scared of a little command line hacking, there’s a better solution: you can reinstall the OS X 10.9 mDNSResponder on a 10.10 system. And after that, all the problems listed above magically go away.

I wouldn’t do that; go back to a full 10.9 system if 10.1 isn’t working for you.

Update (2015-01-13): Paul Horowitz on “How to Flush DNS Cache in OS X Yosemite with discoveryutil”.

Update (2015-03-31): Craig Hockenberry:

Why isn’t there a tech note about all of these DNS issues in Yosemite? Does Apple not care? Or do they not know?

Chris Parker:

It’s known. And the teams care. Don’t know why there isn’t a reunite though.

Craig Hockenberry:

There are A LOT of people burning A LOT of cycles on this stuff. Communication would go a long way…

Update (2017-07-14): See also: Accidental Tech Podcast.

Using HSTS to Track Incognito Users

Sam Greenhalgh (via Yan Zhu):

A security feature of modern web browsers called “HTTP Strict Transport Security” (HSTS) allows a website to indicate that it should always be accessed using a secure connection. If you visit a site that has HSTS enabled, your web browser will remember this flag and ensure the connection is secure any time you visit the website in the future. Subsequent visits to the site without using a secure connection get automatically redirected by the web browser to the secure variant of the web address, beginning https://

This automatic redirecting protects your access to the site from being intercepted but could also be abused by a malicious site to store a unique number to track your web browser. A number can be encoded as a series of bits (true and false values) and stored by accessing a set of web addresses. Each web address responds with HSTS enabled or disabled depending on the address. Once the number is stored it could be read by other sites in the future. Reading the number just requires testing if requests for the same web addresses are redirected or not.


However, unlike cookies, existing HSTS flags are still shared with sites when using “incognito” or “private” windows. The impact is that it’s possible for a site to track you even if you choose to use “incognito” or “private” browsing features in an effort to avoid such tracking.

Considerably more worrying is the behavior displayed by Safari, the default browser for iPad and iPhone. When using Safari on an Apple device there appears to be no way that HSTS flags can be cleared by the user. HSTS flags are even synced with the iCloud service so they will be restored if the device is wiped. In this case the device can effectively be “branded” with an indelible tracking value that you have no way of removing.

Hubble Space Telescope Desktop Pictures

Rob Griffiths:

Last week, I used the just-released Hubble Space Telescope images of the Andromeda galaxy to create a couple of desktop images for my Retina iMac. I liked the results so much that I spent some time collecting other suitable images from the Hubble site, and then cropping and/or scaling them to create interesting high-res desktop images. (I used Acorn for all the edits; it had no troubles, even with TIF images as large as 20,323×16,259!)

Undefined Behavior in C

Mike Ash (via Daniel Jalkut):

It’s possible to invoke undefined behavior in your function. Undefined behavior can mean something never terminates. Thus, it’s possible for your function to never terminate.

If you don’t believe me, I pose the following challenge: give me an implementation of this function. I will then provide a chunk of code that calls it and causes it to enter an infinite loop.

Ember and iCloud Core Data

Dan Counsell:

One of the biggest challenges we faced last year with Ember was sync. Once you start using Ember, it’s incredibly easy to build up a substantial library - and customers upgrading from LittleSnapper have sometimes many thousands more images imported! Multi-gigabyte libraries are not uncommon, and combined with (in particular) iCloud customers have found sync to be problematic. It especially doesn’t help that iCloud is a very hard-to-inspect black box, and there’s no progress shown to you as to the uploaded (or not) state of your library. It’s tough to say it, as iCloud’s robustness has continued to improve each year, but right now iCloud isn‘t a good fit for apps like Ember, and our future product direction will reflect that.

Last year they were optimistic that iCloud Core Data would improve. Now—three plus years after iCloud Core Data shipped—it sounds like they are giving up on it.

Wikipedia Adopts HHVM


Cunningham named his software after a Hawaiian word for “quick.” That’s why the Wikimedia Foundation is happy to report that editing Wikipedia is now twice as quick. Over the last six months we deployed a new technology that speeds up MediaWiki, Wikipedia’s underlying PHP-based code. HipHop Virtual Machine, or HHVM, reduces the median page-saving time for editors from about 7.5 seconds to 2.5 seconds, and the mean page-saving time from about 6 to 3 seconds. Below, I’ll explain the technical background for HHVM on MediaWiki and some of the far-reaching benefits of this change that will go beyond the recent performance gains.


Resolving fidelity issues required some effort, but it turned out well. After we had already been working on the conversion for several months, Facebook approached us offering to donate some developer time to help with this task.

Marco Arment:

A large investment in HHVM or Hack today seems to be worthwhile only if you’re paying much more for PHP CPU usage than engineering salaries, you have a lot of unused engineering capacity to migrate to and maintain the new setup (which takes more effort than official PHP because it’s so bleeding-edge), and your codebase is so large that it’s infeasible to start migrating away from PHP.