Archive for October 12, 2016

Wednesday, October 12, 2016 [Tweets] [Favorites]

Swift Type-Erased Protocol Property

Russ Bishop:

Because _AnyFancyBoxBase adopts FancyProtocol it automatically gains an abstract type member the same way it gains a property or function. It can’t stay abstract though, we need to bind it to something, either a specific type or a generic type parameter.

[…]

Now we can define a subclass of the base box; it inherits the protocol conformance and we provide trampoline functions that forward everything to the instance in var base: Base.

[…]

This type’s raison d’être is in the very first line where we link Base.Thing (the associated type we got from the protocol) to AnyFancyBoxBase.T (the generic parameter on our base class).

[…]

Now we can create our type erasing wrapper. The type it is erasing is the concrete type that adopted FancyProtocol in the first place.

[…]

If we tried to pull this trick with one less type we would end up adding a generic parameter somewhere.

ripgrep

Andrew Gallant (via Hacker News):

In this article I will introduce a new command line search tool, ripgrep, that combines the usability of The Silver Searcher (an ack clone) with the raw performance of GNU grep. ripgrep is fast, cross platform (with binaries available for Linux, Mac and Windows) and written in Rust.

[…]

For both searching single files and huge directories of files, no other tool obviously stands above ripgrep in either performance or correctness.

ripgrep is the only tool with proper Unicode support that doesn’t make you pay dearly for it.

Tools that search many files at once are generally slower if they use memory maps, not faster.

[…]

ripgrep uses a regex engine based on finite automata, so if you want fancy regex features such as backreferences or look around, ripgrep won’t give them to you.

See also: The Treacherous Optimization.

Update (2016-12-05): See also: ripgrep code review (via Hacker News).

BinUtils for Swift

Nicolas Seriot reimplemented parts of the handy Python binascii and struct modules in Swift:

let d = pack("<h2I3sf", [1, 2, 3, "asd", 0.5])
assert(d == unhexlify("0100 02000000 03000000 617364 0000003f"))

Yahoo’s FISA E-mail Scan

Charlie Savage and Nicole Perlroth (via MacRumors):

A system intended to scan emails for child pornography and spam helped Yahoo satisfy a secret court order requiring it to search for messages containing a computer “signature” tied to the communications of a state-sponsored terrorist organization, several people familiar with the matter said on Wednesday.

Two government officials who spoke on the condition of anonymity said the Justice Department obtained an individualized order from a judge of the Foreign Intelligence Surveillance Court last year. Yahoo was barred from disclosing the matter.

To comply, Yahoo customized an existing scanning system for all incoming email traffic, which also looks for malware, according to one of the officials and to a third person familiar with Yahoo’s response, who also spoke on the condition of anonymity.

David Kravets:

At its most basic level, this newly surfaced tool exposes another US digital surveillance program. It differs from so-called “upstream” spying in which the authorities tap directly into the Internet backbone and scan for certain search terms—a spying program with diminishing returns as more and more data on the Internet has become encrypted. This Yahoo situation is also different from the Prism program, where the authorities acquire customer data from tech companies matching chosen search selectors.

David Sparks:

Yahoo has responded that Reuter’s original reporting of this was “misleading”, But again how would we really know? All of this is done under the veil of secrecy.

Joseph Menn:

The court-ordered search Yahoo conducted, on the other hand, was done by a module attached to the Linux kernel - in other words, it was deeply buried near the core of the email server operating system, far below where mail sorting was handled, according to three former Yahoo employees.

They said that made it hard to detect and also made it hard to figure out what the program was doing.

Lorenzo Franceschi-Bicchierai (via Slashdot):

The spy tool that the US government ordered Yahoo to install on its systems last year at the behest of the NSA or the FBI was a “poorly designed” and “buggy” piece of malware, according to two sources closely familiar with the matter.

[…]

Anonymous sources told The Times that the tool was nothing more than a modified version of Yahoo’s existing scanning system, which searches all email for malware, spam and images of child pornography.

But two sources familiar with the matter told Motherboard that this description is wrong, and that the tool was actually more like a “rootkit,” a powerful type of malware that lives deep inside an infected system and gives hackers essentially unfettered access.

Bruce Schneier:

Other companies have been quick to deny that they did the same thing, but I generally don’t believe those carefully worded statements about what they have and haven’t done.

Previously: Yahoo Says Hackers Stole Data on 500 Million Users in 2014.

What’s New in Safari 10

Apple (Hacker News):

Safari’s IndexedDB implementation now fully supports the recommended standard. You may now use the API to store structured data for web applications that work offline or that require large amounts of client-side data caching.

Use JavaScript commands to programmatically cut and copy text to the clipboard with document.execCommand('cut') and document.execCommand('copy').

[…]

Safari 10 brings Picture in Picture to macOS so users can watch video in a separate, resizable window that stays on top of other application windows and remains on-screen when switching desktop spaces.

[…]

You can give customers an easy, secure, and private way to pay for physical goods and services—such as groceries, clothing, tickets, reservations, and more. Users can check out with a single touch using Apple Pay with Touch ID on their iPhone, or by double-clicking the side button on Apple Watch.

[…]

You can now create macOS-native Safari app extensions to sell and distribute in the App Store.

Ricky Mondello:

And one of my favorite things about Safari 10: ⌘Z will reopen more than one closed tab, and ⇧⌘T will restore closed tabs and windows.

Simone Manganelli:

Safari 10. :epic eyeroll: “On iOS, videos without audio tracks or with disabled audio tracks can play automatically when the webpage loads.”

Rosyna Keller:

Correct, it’s so H.264 can replace animated GIFs. It’s all detailed in a WebKit blog post.

Jeff Johnson:

WebKitMinimumFontSize doesn’t seem to work anymore.

Update (2016-10-12): Jeff Nouwen:

I like the “close tab and go back to the parent tab on Back” feature, implemented with “parent-tab://”.

Jeff Benjamin:

Although YouTube’s player doesn’t make it readily apparent that its videos work with Picture-in-Picture, it’s quite easy to enable the handy feature for all of your favorite YouTube videos on Safari.

[…]

Step 1: Right click on the YouTube video that you wish to detach

Step 2: Once the menu appears, right-click once more to reveal a second menu and then click Enter Picture-in-Picture