<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>phatblat&apos;s reflog</title>
    <description>a few SHAs from a journey through code</description>
    <link>https://phatbl.at/</link>
    <atom:link href="https://phatbl.at/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sat, 04 May 2024 10:53:01 -0600</pubDate>
    <lastBuildDate>Sat, 04 May 2024 10:53:01 -0600</lastBuildDate>
    <generator>Jekyll v4.3.3</generator>
    
      <item>
        <title>Intercepting stdout in Swift</title>
        <description>&lt;p&gt;In the process of creating tests for &lt;a href=&quot;https://github.com/mas-cli/mas&quot;&gt;mas&lt;/a&gt;,
I needed to validate the text that was being output to stdout for the user.
One way to do this would be to introduce a façade for output.
This output controller would have a production version that uses the typical &lt;code&gt;print&lt;/code&gt;
function and the test version stores the strings sent to it so that the values
can be compared to the expected values. However, I figured I would try to
intercept character data sent to stdout instead. While this isn’t too difficult,
restoring the original stdout ended up being rather tricky as there wasn’t a good
example to copy.&lt;/p&gt;

&lt;h2 id=&quot;objectives&quot;&gt;Objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Store characters written to stdout in a &lt;code&gt;String&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Pass the unmodified data through so it can be viewed in the Xcode console&lt;/li&gt;
  &lt;li&gt;Only used for unit tests&lt;/li&gt;
  &lt;li&gt;Don’t break anything&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;research&quot;&gt;Research&lt;/h2&gt;

&lt;p&gt;As the first step in &lt;a href=&quot;https://dzone.com/articles/stack-overflow-driven-development-sodd-its-really&quot;&gt;SODD&lt;/a&gt;,
I made sure to Google whether anyone had figured this out before.
@ericasadun has a great post on
&lt;a href=&quot;https://ericasadun.com/2015/05/22/swift-logging/&quot;&gt;Swift Logging&lt;/a&gt;,
but it’s from the Swift 1-2 days and a bit dated now. Plus, I dislike calling C
functions from Swift and want to minimize the use of C APIs.&lt;/p&gt;

&lt;p&gt;I found a newer post by @thesaadismail on
&lt;a href=&quot;https://medium.com/@thesaadismail/eavesdropping-on-swifts-print-statements-57f0215efb42&quot;&gt;Eavesdropping on Swift’s Print Statements&lt;/a&gt;
which served as my starting point. There are a few key points in his post:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;dup2&lt;/code&gt; can be used to connect a &lt;code&gt;Pipe&lt;/code&gt; to an existing file handle like stdout&lt;/li&gt;
  &lt;li&gt;use both an input &lt;code&gt;Pipe&lt;/code&gt; and an output &lt;code&gt;Pipe&lt;/code&gt; if you want to have output continue to appear in the Xcode console&lt;/li&gt;
  &lt;li&gt;don’t read from &lt;code&gt;Pipe&lt;/code&gt;s directly as they will block the current thread
    &lt;ul&gt;
      &lt;li&gt;instead use &lt;code&gt;readInBackgroundAndNotify()&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;

&lt;p&gt;I created a class to hold this funcationality so that it could be reused by different tests.&lt;/p&gt;

&lt;h3 id=&quot;outputlistener&quot;&gt;OutputListener&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;class OutputListener {
    /// consumes the messages on STDOUT
    let inputPipe = Pipe()

    /// outputs messages back to STDOUT
    let outputPipe = Pipe()

    /// Buffers strings written to stdout
    var contents = &amp;quot;&amp;quot;
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Here we have the minimal storage for my implementation. &lt;code&gt;inputPipe&lt;/code&gt; will bring input to
my test listener, &lt;code&gt;outputPipe&lt;/code&gt; will handle sending text back to stdout and &lt;code&gt;contents&lt;/code&gt;
will build up a string of all the data that passes through.&lt;/p&gt;

&lt;h3 id=&quot;init&quot;&gt;init&lt;/h3&gt;

&lt;p&gt;One-time setup code to wire up the two &lt;code&gt;Pipe&lt;/code&gt;s and capture &lt;code&gt;contents&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;init() {
    // Set up a read handler which fires when data is written to our inputPipe
    inputPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in
        guard let strongSelf = self else { return }

        let data = fileHandle.availableData
        if let string = String(data: data, encoding: String.Encoding.utf8) {
            strongSelf.contents += string
        }

        // Write input back to stdout
        strongSelf.outputPipe.fileHandleForWriting.write(data)
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This uses &lt;code&gt;readabilityHandler&lt;/code&gt; instead of notifications for less code and no need to
repeatedly call &lt;code&gt;readInBackgroundAndNotify()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;While trying to get this to actually work, I found that calling either &lt;code&gt;readDataToEndOfFile()&lt;/code&gt;
or &lt;code&gt;readData(ofLength:)&lt;/code&gt; immediately blocks the current thread seemingly forever. This may be
because my &lt;code&gt;inputPipe&lt;/code&gt; is still open so the file has no “end”.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;availableData&lt;/code&gt; is the property to use as it will have a &lt;code&gt;Data&lt;/code&gt; object of the character data
written to the pipe’s file handle so far.&lt;/p&gt;

&lt;h3 id=&quot;openconsolepipe&quot;&gt;openConsolePipe&lt;/h3&gt;

&lt;p&gt;This is the code that actually wires up the pipes to intercept stdout. It uses the esoteric
&lt;code&gt;dup2&lt;/code&gt; C function.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;/// Sets up the &amp;quot;tee&amp;quot; of piped output, intercepting stdout then passing it through.
func openConsolePipe() {
    // Copy STDOUT file descriptor to outputPipe for writing strings back to STDOUT
    dup2(stdoutFileDescriptor, outputPipe.fileHandleForWriting.fileDescriptor)

    // Intercept STDOUT with inputPipe
    dup2(inputPipe.fileHandleForWriting.fileDescriptor, stdoutFileDescriptor)
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code&gt;stdoutFileDescriptor&lt;/code&gt; is my computed property for &lt;code&gt;FileHandle.standardOutput.fileDescriptor&lt;/code&gt;,
which is the same value as &lt;code&gt;STDOUT_FILENO&lt;/code&gt;, or simply &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This works, but it’s the one piece of magic from @thesaadismail’s post that I don’t
fully understand. The calls to &lt;code&gt;dup2&lt;/code&gt; return the 2nd argument’s value indicating success,
however there was no change to any &lt;code&gt;fileDescriptor&lt;/code&gt; property values as I was expecting.
&lt;code&gt;FileHandle.fileDescriptor&lt;/code&gt; is read-only so perhaps the Swift Foundation functionality
doesn’t refresh this value.&lt;/p&gt;

&lt;p&gt;Things went swimmingly at this point when running a single test. However, when I ran the entire
&lt;code&gt;mas&lt;/code&gt; test suite some calls to &lt;code&gt;print()&lt;/code&gt; would blow up with &lt;code&gt;SIGPIPE&lt;/code&gt; 💥.&lt;/p&gt;

&lt;h3&gt;😕&lt;/h3&gt;

&lt;p&gt;It was clear to me that monkeying with stdout was causing these issues. I attempted to use &lt;code&gt;dup2&lt;/code&gt;
to restore stdout to no avail.&lt;/p&gt;

&lt;h3 id=&quot;-1&quot;&gt;💡&lt;/h3&gt;

&lt;p&gt;Then I recalled an experiment I did a few years ago to suppress all output to stdout in a little
project called &lt;a href=&quot;https://github.com/phatblat/nolog/blob/master/NoLog/NoLog/ThisClassLoadsFirst.m#L17&quot;&gt;nolog&lt;/a&gt;.
it uses &lt;code&gt;freopen()&lt;/code&gt; to reopen stdout, pointing it to a new file path. nolog redirects stdout to
&lt;code&gt;/dev/null&lt;/code&gt;, a well-known way to ignore output from a terminal command.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code&gt;echo &quot;can anyone hear me?&quot; &amp;gt; /dev/null&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Digging around in the &lt;code&gt;/dev&lt;/code&gt; directory revealed that macOS has a &lt;code&gt;/dev/stdout&lt;/code&gt; file, so I gave that a whirl.&lt;/p&gt;

&lt;h3 id=&quot;closeconsolepipe&quot;&gt;closeConsolePipe&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;/// Tears down the &amp;quot;tee&amp;quot; of piped output.
func closeConsolePipe() {
    // Restore stdout
    freopen(&amp;quot;/dev/stdout&amp;quot;, &amp;quot;a&amp;quot;, stdout)

    [inputPipe.fileHandleForReading, outputPipe.fileHandleForWriting].forEach { file in
        file.closeFile()
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;🎉 This was the missing piece I needed to restore stdout. I don’t know if the &lt;code&gt;closeFile()&lt;/code&gt;
calls are necessary, especially in a test suite, but I like to clean up after myself 🧹.&lt;/p&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;p&gt;Here’s how it works inside a test.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;let output = OutputListener()
output.openConsolePipe()
let expectedOutput = &amp;quot;hi there&amp;quot;

// run code under test that output some text
print(expectedOutput, terminator: &amp;quot;&amp;quot;)

// output is async so need to wait for contents to be updated
expect(output.contents).toEventuallyNot(beEmpty())
expect(output.contents) == expectedOutput

output.closeConsolePipe()
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Here I’m using the Nimble &lt;a href=&quot;https://github.com/Quick/Nimble/blob/master/Sources/Nimble/Matchers/Async.swift#L142-L148&quot;&gt;&lt;code&gt;toEventuallyNot&lt;/code&gt;&lt;/a&gt;
function to take care of the asynchroncity of these file handles as they are
essentially text streams. If you are using XCTest, take a look at
&lt;a href=&quot;https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations/testing_asynchronous_operations_with_expectations&quot;&gt;Testing Asynchronous Operations with Expectations&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mas-cli/mas/blob/master/MasKitTests/OutputListener.swift&quot;&gt;&lt;code&gt;OutputListener.swift&lt;/code&gt;&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;used in &lt;a href=&quot;https://github.com/mas-cli/mas/blob/master/MasKitTests/Commands/InfoCommandSpec.swift#L55-L68&quot;&gt;&lt;code&gt;info&lt;/code&gt; command tests&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/phatblat/nolog/blob/master/NoLog/NoLog/ThisClassLoadsFirst.m#L17&quot;&gt;nolog&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://medium.com/@thesaadismail/eavesdropping-on-swifts-print-statements-57f0215efb42&quot;&gt;Eavesdropping on Swift’s Print Statements&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://ericasadun.com/2015/05/22/swift-logging/&quot;&gt;Swift Logging&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations/testing_asynchronous_operations_with_expectations&quot;&gt;Testing Asynchronous Operations with Expectations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://kelan.io/2015/the-weak-strong-dance-in-swift/&quot;&gt;The Weak/Strong Dance in Swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.computerhope.com/jargon/s/stdout.htm&quot;&gt;stdout&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://man7.org/linux/man-pages/man1/tee.1.html&quot;&gt;tee command&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/a/18963142/39207&quot;&gt;&lt;code&gt;SIGPIPE&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;api-docs&quot;&gt;API Docs&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/pipe&quot;&gt;&lt;code&gt;Pipe&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/filehandle&quot;&gt;&lt;code&gt;FileHandle&lt;/code&gt;&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/filehandle/1412413-readabilityhandler&quot;&gt;&lt;code&gt;readabilityHandler&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/filehandle/1411463-availabledata&quot;&gt;&lt;code&gt;availableData&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/filehandle/1411490-readdatatoendoffile&quot;&gt;&lt;code&gt;readDataToEndOfFile()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/foundation/filehandle/1413916-readdata&quot;&gt;&lt;code&gt;readData(ofLength:)&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://linux.die.net/man/2/dup2&quot;&gt;&lt;code&gt;dup2()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://linux.die.net/man/3/freopen&quot;&gt;&lt;code&gt;freopen()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/swift/1541053-print&quot;&gt;&lt;code&gt;print(_:separator:terminator:)&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/xctest/xctestexpectation&quot;&gt;&lt;code&gt;XCTestExpectation&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Tue, 08 Jan 2019 00:00:00 -0700</pubDate>
        <link>https://phatbl.at/2019/01/08/intercepting-stdout-in-swift.html</link>
        <guid isPermaLink="true">https://phatbl.at/2019/01/08/intercepting-stdout-in-swift.html</guid>
        
        
      </item>
    
      <item>
        <title>UISearchController</title>
        <description>&lt;p&gt;A “search controller” is the thing behind a &lt;code&gt;UISearchBar&lt;/code&gt; on iOS that is responsible for showing and hiding the “search results” screen (typically a table view) and updating the results in response to changes to the search term, character by character.&lt;/p&gt;

&lt;p&gt;Let’s go through the setup of a very simple search controller for an iOS app. It will display a list of Swift keywords in a table and filter them in response to text entered into the search bar.&lt;/p&gt;

&lt;h2 id=&quot;search-bar&quot;&gt;Search Bar&lt;/h2&gt;

&lt;p&gt;What’s unexpected about &lt;code&gt;UISearchController&lt;/code&gt; is that you have to &lt;em&gt;install&lt;/em&gt; its &lt;code&gt;searchBar&lt;/code&gt; into the view hierarchy. You can’t connect it to an existing &lt;code&gt;UISearchBar&lt;/code&gt; defined in a storyboard.&lt;sup id=&quot;fnref:searchbar-storyboard&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:searchbar-storyboard&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; If you’re just adding the search bar to the top of a table, like in Apple’s sample code&lt;sup id=&quot;fnref:apple-sample-code&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:apple-sample-code&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;, you can just make it the &lt;code&gt;tableHeaderView&lt;/code&gt;. But just about any other situation is going to have to deal with auto layout.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;override func viewDidLoad() {
  super.viewDidLoad()
  let searchBar = searchController.searchBar
  searchBar.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
  searchBarContainerView.addSubview(searchBar)
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We’re going to reserve some space in the UI using a “container” view&lt;sup id=&quot;fnref:container-view&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:container-view&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;. This will show where the search bar will eventually be in the storyboard to give an idea of how it will fit with other UI elements. Also, constraints can be tied to the container view in the storyboard so that none need to be installed in code.&lt;/p&gt;

&lt;center&gt;
&lt;img src=&quot;/images/uisearchcontroller-main-scene.png&quot; width=&quot;300&quot; alt=&quot;&apos;Main scene showing search bar container view&apos;&quot; title=&quot;Main scene&quot; /&gt;
&lt;/center&gt;

&lt;h2 id=&quot;search-results-controller&quot;&gt;Search Results Controller&lt;/h2&gt;

&lt;p&gt;The search results controller is just a simple &lt;code&gt;UITableViewController&lt;/code&gt; with each cell displaying a single Swift keyword.&lt;/p&gt;

&lt;center&gt;
&lt;img src=&quot;/images/uisearchcontroller-search-results.png&quot; width=&quot;300&quot; alt=&quot;&apos;Search results table showing a list of swift keywords&apos;&quot; title=&quot;Search results&quot; /&gt;
&lt;/center&gt;

&lt;h2 id=&quot;search-controller&quot;&gt;Search Controller&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;UISearchController&lt;/code&gt; must be set up in code and it’s constructor takes a single argument - a &lt;code&gt;UIViewController&lt;/code&gt; which is going to display the search results. Here we pass in a reference to our &lt;code&gt;searchResultsController&lt;/code&gt; stored in a property.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;let searchController =
  UISearchController(searchResultsController: self.searchResultsController)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.delegate = self

searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;There is little interaction with &lt;code&gt;UISearchController&lt;/code&gt; beyond creating one, configuring it and connecting it to the following:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;the search results controller&lt;/li&gt;
  &lt;li&gt;a &lt;code&gt;UISearchResultsUpdating&lt;/code&gt; (the &lt;code&gt;searchResultsUpdater&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;a &lt;code&gt;UISearchControllerDelegate&lt;/code&gt; (optional)&lt;/li&gt;
  &lt;li&gt;a &lt;code&gt;UISearchBarDelegate&lt;/code&gt; (optional)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;search-results-updater&quot;&gt;Search Results Updater&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;UISearchResultsUpdating&lt;/code&gt; protocol is very simple, but it’s where all the fun happens:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func updateSearchResultsForSearchController(searchController: UISearchController)
  guard let searchTerm = searchController.searchBar.text else { return }
  // use searchTerm to filter search results
  ...
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This method is called whenever the text changes in the search bar. The current text can be accessed through the &lt;code&gt;searchController&lt;/code&gt; parameter. Any object can handle these updates.&lt;/p&gt;

&lt;p&gt;It’s common to also make the search results controller the &lt;code&gt;searchResultsUpdater&lt;/code&gt; and have it conform to the &lt;code&gt;UISearchResultsUpdating&lt;/code&gt; protocol. That configuration causes the search results controller to update itself with each change to the search term. However, we’re not going that route because of a special case we want to handle: a custom “empty results” view. Attempting to add a subview to a &lt;code&gt;UITableView&lt;/code&gt; is fraught with peril, so we’re not going to do that.&lt;/p&gt;

&lt;center&gt;
&lt;img src=&quot;/images/uisearchcontroller-no-results.png&quot; width=&quot;300&quot; alt=&quot;&apos;Empty search results screen&apos;&quot; title=&quot;Empty search results&quot; /&gt;
&lt;/center&gt;

&lt;p&gt;Instead the “main” view controller will be the &lt;code&gt;searchResultsUpdater&lt;/code&gt; and it will pass the current &lt;code&gt;searchTerm&lt;/code&gt; into the search results controller. The search results controller will take care of filtering and return the number of results displayed.&lt;/p&gt;

&lt;p&gt;The “main” view controller will use the number of results displayed to determine when to show and hide the “no results” view.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;  ...
  let displayedResultCount = searchResultsController.filterData(searchTerm)
  handleEmptyResults(displayedResultCount)
}

func handleEmptyResults(displayedResults: Int) {
  let showEmptyResultsView = (searchController.active &amp;amp;&amp;amp; displayedResults == 0)
  emptyResultsView.hidden = !showEmptyResultsView
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This &lt;code&gt;emptyResultsView&lt;/code&gt; is defined in the storyboard and initially hidden.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;That’s pretty much it. I wanted to provide a simple example because there’s a lot of confusing information out there on how this API works. Web searches are tainted with the old API since the type names are so similar.&lt;sup id=&quot;fnref:search-display-controller&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:search-display-controller&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete project on GitHub at the URL below:
&lt;strong&gt;&lt;a href=&quot;https://github.com/phatblat/SearchController&quot;&gt;https://github.com/phatblat/SearchController&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The only other interesting aspect of this sample project is how the &lt;a href=&quot;https://github.com/phatblat/SearchController/blob/master/SearchController/SwiftKeyword.swift&quot;&gt;Swift keywords are escaped&lt;/a&gt; to serve as enum member values. Sure, it’s easier to store them as strings but where’s the fun in that?&lt;/p&gt;

&lt;h2 id=&quot;other-types-of-search-results&quot;&gt;Other Types of Search Results&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;UISearchController&lt;/code&gt; is not coupled with the presentation of the search results, so we are free to use any kind of view controller to handle it. At &lt;a href=&quot;http://360idev.com&quot;&gt;360|iDev 2015&lt;/a&gt;, @jeremiahgage presented using a &lt;a href=&quot;https://github.com/phatblat/360iDev-Slides/blob/master/2015-Slides.md#uisearchcontroller-with-a-uicollectionview&quot;&gt;UISearchController with a UICollectionView&lt;/a&gt; which is a fabulous example especially since &lt;code&gt;UICollectionView&lt;/code&gt; is so highly customizable.&lt;/p&gt;

&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:searchbar-storyboard&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This was how the old, deprecated &lt;a href=&quot;https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchDisplayController_Class/&quot;&gt;&lt;code&gt;UISearchDisplayController&lt;/code&gt;&lt;/a&gt; was often set up. There is even still a template for it in the Interface Builder Object library. &lt;img src=&quot;/images/uisearchcontroller-search-bar-and-search-display-controller.png&quot; alt=&quot;Search Bar and Search Display Controller in Interface Builder Object library pane&quot; /&gt; &lt;a href=&quot;#fnref:searchbar-storyboard&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:apple-sample-code&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;The &lt;a href=&quot;https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchController/#//apple_ref/doc/uid/TP40014432-CH1-SW8&quot;&gt;UISearchController&lt;/a&gt; reference documentation contains a minimal code sample. &lt;a href=&quot;#fnref:apple-sample-code&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:container-view&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Nothing as fancy as &lt;a href=&quot;https://www.objc.io/issues/1-view-controllers/containment-view-controller/&quot;&gt;View Controller Containment&lt;/a&gt;. Just a simple &lt;code&gt;UIView&lt;/code&gt; which we’ll be using as the parent view for the &lt;code&gt;UISearchBar&lt;/code&gt;. &lt;a href=&quot;#fnref:container-view&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:search-display-controller&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Do yourself a favor and never look at the API for &lt;code&gt;UISearchDisplayController&lt;/code&gt; - it’s deprecated anyway. I’m constantly confusing the two. &lt;a href=&quot;#fnref:search-display-controller&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 10 May 2016 22:31:31 -0600</pubDate>
        <link>https://phatbl.at/2016/05/10/uisearchcontroller.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/05/10/uisearchcontroller.html</guid>
        
        <category>swift,</category>
        
        <category>ios,</category>
        
        <category>tableview</category>
        
        
      </item>
    
      <item>
        <title>Outlets Pod</title>
        <description>&lt;style&gt;
.center-image
{
  margin: 0 auto;
  display: block;
}
&lt;/style&gt;

&lt;p&gt;Inspired by the great work that came out of writing &lt;a href=&quot;/2016/04/29/testing-iboutlets-and-ibactions-with-curried-functions-in-swift.html&quot;&gt;Testing IBOutlets&lt;/a&gt; (and the wonderful help I got through &lt;a href=&quot;https://gist.github.com/phatblat/ee2c470970b906238e395c4fd48f4ad3&quot;&gt;sharing&lt;/a&gt; the &lt;a href=&quot;https://github.com/phatblat/OutletActionAssertion&quot;&gt;code&lt;/a&gt;), I’ve created a micro-library which contains these testing functions to make it easy to include them in a project. &lt;a href=&quot;https://github.com/phatblat/Outlets&quot;&gt;Outlets&lt;/a&gt; is live now on &lt;a href=&quot;https://cocoapods.org/pods/Outlets&quot;&gt;CocoaPods&lt;/a&gt; and can also be built with Carthage, if that’s your poison.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/phatblat/Outlets&quot;&gt;&lt;img src=&quot;http://community.imgtec.com/wp-content/uploads/sites/2/2014/09/fork-me-on-github.png&quot; alt=&quot;GitHub button&quot; title=&quot;Fork me on GitHub button&quot; class=&quot;center-image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For now, the library only works with iOS apps as these utility functions depend on UIKit. I’ll be looking into support for OS X, tvOS and watchOS (if we get &lt;a href=&quot;https://openradar.appspot.com/21760513&quot;&gt;XCTest support for it&lt;/a&gt; in June :wink:).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/outlets-logo.png&quot; alt=&quot;Outlets logo&quot; title=&quot;Outlets logo showing electrical sockets from various contries&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Why don’t you give it a good ol’ &lt;code&gt;pod try Outlets&lt;/code&gt;?&lt;/p&gt;

</description>
        <pubDate>Tue, 03 May 2016 21:06:22 -0600</pubDate>
        <link>https://phatbl.at/2016/05/03/outlets-pod.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/05/03/outlets-pod.html</guid>
        
        <category>swift,</category>
        
        <category>cocoapods,</category>
        
        <category>carthage,</category>
        
        <category>ios</category>
        
        
      </item>
    
      <item>
        <title>Testing IBOutlets and IBActions With Curried Functions in Swift</title>
        <description>&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; These nifty utility functions are now available as the &lt;a href=&quot;/2016/05/03/outlets-pod.html&quot;&gt;Outlets Pod&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This post is a eulogy to the syntactic-sugar :lollipop: syntax for curried functions in Swift 1-2.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;iboutlet-testing&quot;&gt;IBOutlet Testing&lt;/h2&gt;

&lt;p&gt;A couple years ago I built a universal iPhone / iPad app with three storyboards.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;iPhone&lt;/li&gt;
  &lt;li&gt;iPad&lt;/li&gt;
  &lt;li&gt;shared scenes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/firefly-storyboards.png&quot; alt=&quot;&quot; title=&quot;iPad, iPhone and shared storyboards&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Many of the view controllers between the device-specific storyboards were shared and thus the outlets and actions all had to be the same. Each outlet property was bound to two different storyboards and required launching the app in different simulators to manually validate they were hooked up correctly. It was a constant challenge to keep them in sync whenever renaming a property or method. Most of the time I would forget to update at least one outlet and I’d have another lovely crasher from the device I forgot to test on.&lt;/p&gt;

&lt;p&gt;I came up with a scheme to use unit tests to assert that these outlets and actions were bound correctly so that I could validate them almost instantly. I ended up with a handful of ugly C functions that I never shared.&lt;/p&gt;

&lt;p&gt;It’s much easier nowadays to build a universal iPhone/iPad app with shared storyboards due to &lt;a href=&quot;https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html&quot;&gt;Size Classes&lt;/a&gt;. The new &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2015/406/&quot;&gt;UI Testing&lt;/a&gt; in Xcode 7 makes it much easier to automate testing, which can catch any missed outlet/action bindings (as long as your test touches every UI element). However, I still find this sort of low-level assertion helpful, especially since it’s so easy to do.&lt;/p&gt;

&lt;h2 id=&quot;swift-curried-functions&quot;&gt;Swift Curried Functions&lt;/h2&gt;

&lt;p&gt;When I learned that Swift had super-clean function currying syntax I refactored these ugly helper functions into something much more beautiful, learning about a new language feature in the process.&lt;/p&gt;

&lt;p&gt;Swift 2 has syntactic sugar for defining curried functions.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func sum(A: Int)(_ B: Int)(_ C: Int) -&amp;gt; Int {
  return A + B + C
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This &lt;code&gt;sum&lt;/code&gt; function can be called in a number of ways:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;let sumA = sum(1)     // Int -&amp;gt; Int -&amp;gt; Int
let sumAB = sumA(2)   // Int -&amp;gt; Int

sum(1)(2)(3)          // 6
sumA(2)(3)            // 6
sumAB(3)              // 6
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this example, the &lt;code&gt;sumA&lt;/code&gt; function has captured the value of the &lt;code&gt;A&lt;/code&gt; parameter (1), whereas &lt;code&gt;sumAB&lt;/code&gt; has captured the values of both the &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; parameters (1 and 2). When the final &lt;code&gt;C&lt;/code&gt; parameter is passed to any of these functions the resulting &lt;code&gt;Int&lt;/code&gt; value (6) is returned.&lt;/p&gt;

&lt;p&gt;An equivalent &lt;code&gt;sum&lt;/code&gt; function using the more verbose curried function syntax shows that it is really a set of nested functions.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func sum(A: Int) -&amp;gt; (Int -&amp;gt; (Int -&amp;gt; Int)) {
  return { B in
    return { C in
      return A + B + C
    }
  }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This more verbose syntax can get noisy very quickly with many arguments. It’s a common practice to define a &lt;code&gt;curry&lt;/code&gt; function which transforms a multi-parameter function into its curried version. &lt;sup id=&quot;fnref:curry-func&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:curry-func&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func curry(f: (A,B)-&amp;gt;C) -&amp;gt; A-&amp;gt;B-&amp;gt;C
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The thoughtbot &lt;a href=&quot;https://github.com/thoughtbot/Curry/blob/master/Source/Curry.swift&quot;&gt;Curry library&lt;/a&gt; has all the variations of the &lt;code&gt;curry&lt;/code&gt; function up to 19 parameters.&lt;/p&gt;

&lt;h2 id=&quot;why-currying&quot;&gt;Why Currying?&lt;/h2&gt;

&lt;p&gt;Currying helps to simplify these outlet and action test functions so that the view controller doesn’t have to be passed in every function call. Just like the &lt;code&gt;sumA&lt;/code&gt; function holds onto the value of the first parameter, these test functions hold onto a reference to the view controller being tested. There’s also the benefit of being able to give the returned function a very readable name.&lt;/p&gt;

&lt;h2 id=&quot;outlet-assertion&quot;&gt;Outlet Assertion&lt;/h2&gt;

&lt;p&gt;Just look at how beautiful this is!&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;it(&amp;quot;has a leftButton outlet&amp;quot;) {
  hasButtonOutlet(&amp;quot;leftButton&amp;quot;)
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;This is a BDD-style test using the &lt;a href=&quot;https://github.com/Quick/Quick&quot;&gt;Quick&lt;/a&gt; framework.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, what is that &lt;code&gt;hasButtonOutlet&lt;/code&gt; magic? It’s a &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Partial_application&quot;&gt;partially-applied&lt;/a&gt; function saved in a local variable. This is how it is created:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;class ViewControllerSpec: QuickSpec {
  override func spec() {
    var viewController: UIViewController!
    var hasButtonOutlet: (String -&amp;gt; UIButton?)!
    describe(&amp;quot;view controller&amp;quot;) {
      beforeEach {
        viewController = ...
        hasButtonOutlet = outlet(viewController)
      }
      ...
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The return type in the &lt;code&gt;hasButtonOutlet&lt;/code&gt; declaration (&lt;code&gt;UIButton&lt;/code&gt; in the above example) is the type used for validation inside the generic &lt;code&gt;outlet&lt;/code&gt; function below.&lt;/p&gt;

&lt;p&gt;Calling the &lt;code&gt;outlet&lt;/code&gt; full function would look like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;outlet(viewController)(&amp;quot;leftDoneButton&amp;quot;)
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;But, you might as well just have a plain, old multi-parameter function if you want all that. Currying reduces noise and makes these tests more readable - Handy when you have dozens of outlets and are chasing down which one you mistyped.&lt;/p&gt;

&lt;p&gt;Here is a condensed definition of the &lt;code&gt;outlet&lt;/code&gt; curried function:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func outlet&amp;lt;T&amp;gt;(viewController: UIViewController) -&amp;gt; (String) -&amp;gt; T? {
  return { (expectedOutlet: String) -&amp;gt; T? in
    guard let object = viewController.valueForKey(expectedOutlet)
      else { fail(&amp;quot;\(expectedOutlet) outlet was nil&amp;quot;); return nil }

    guard let objectOfType = object as? T
      else { fail(&amp;quot;\(object) outlet was not a \(T.self)&amp;quot;); return nil }

    return objectOfType
  }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;The &lt;code&gt;fail&lt;/code&gt; function is part of the &lt;a href=&quot;https://github.com/Quick/Nimble&quot;&gt;Nimble&lt;/a&gt; matcher framework&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;action-assertion&quot;&gt;Action Assertion&lt;/h2&gt;

&lt;p&gt;The action assertion functions are similarly simple.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;it(&amp;quot;receives a didTapLeftButton: action from leftButton&amp;quot;) {
  receivesAction(&amp;quot;didTapLeftButton:&amp;quot;, from: &amp;quot;leftButton&amp;quot;)
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;One caveat is that they require an outlet on the thing sending the action. A lot of the time an outlet isn’t necessary for an action-sending UI element, but I haven’t found a way to get the actions from the view controller (yet).&lt;/p&gt;

&lt;p&gt;Here is the setup for the partially-applied &lt;code&gt;receivesAction&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;class ViewControllerSpec: QuickSpec {
    override func spec() {
    var receivesAction: ((String, from: String) -&amp;gt; Void)!
    describe(&amp;quot;view controller&amp;quot;) {
      beforeEach {
        viewController = ...
        receivesAction = action(viewController)
      }
      ...
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Implementation of the &lt;code&gt;action&lt;/code&gt; function is more complex as getting to the IBAction differs depending on whether the UI element is a &lt;code&gt;UIBarButtonItem&lt;/code&gt; or a type of &lt;code&gt;UIControl&lt;/code&gt;. &lt;sup id=&quot;fnref:action-test&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:action-test&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func action(viewController: UIViewController) -&amp;gt; (String, from: String) -&amp;gt; Void {
  return { (expectedAction: String, expectedOutlet: String) in
    let optionalControl = outlet(viewController)(expectedOutlet)

    var target: AnyObject?
    var action: String?

    if let control = optionalControl {
      switch control {
      case let button as UIBarButtonItem:
        target = button.target
        action = button.action.description
      case let control as UIControl:
        target = control.allTargets().first!
        var allActions: [String] = []
        for event: UIControlEvents in [.TouchUpInside, .ValueChanged] {
          allActions += control.actionsForTarget(target!, forControlEvent: event) ?? []
        }

        // Filter down to the expected action
        action = allActions.filter({$0 == expectedAction}).first
      default:
        fail(&amp;quot;Unhandled control type: \(control.dynamicType)&amp;quot;)
      }
    }

    expect(target) === viewController
    expect(action).toNot(beNil())
    if let action = action {
      expect(action) == expectedAction
    }
  }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;The &lt;code&gt;expect&lt;/code&gt; function is part of the &lt;a href=&quot;https://github.com/Quick/Nimble&quot;&gt;Nimble&lt;/a&gt; matcher framework&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;A full project demonstrating these helper functions is available at:
&lt;a href=&quot;https://github.com/phatblat/OutletActionAssertion&quot;&gt;https://github.com/phatblat/OutletActionAssertion&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The functions in the sample code are much more beautiful due to @esttorhe’s help in simplifying the API.&lt;/p&gt;

&lt;p&gt;Running the tests in the example project gives quick&lt;sup id=&quot;fnref:quick&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:quick&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; feedback that all the outlets and actions are properly connected without even launching the app.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/outlet-action-tests-pass.png&quot; alt=&quot;&quot; title=&quot;ViewControllerSpec test status with all green checkmarks&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;deprecated-sob&quot;&gt;Deprecated :sob:&lt;/h2&gt;

&lt;p&gt;Shortly after @allonsykraken posted &lt;a href=&quot;http://krakendev.io/blog/hipster-swift&quot;&gt;Hipster Swift&lt;/a&gt;, I learned that the super-clean syntactic sugar version of curried functions is &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md&quot;&gt;going away in Swift 3&lt;/a&gt;&lt;sup id=&quot;fnref:swift3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:swift3&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; and it made me sad. While this is a more esoteric language feature, I really like how curried functions can be used to simplify an API. Also, the way Swift implemented curried functions made them so easy to use.&lt;/p&gt;

&lt;p&gt;Isn’t this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func fourChainedFunctions(a: Int)(b: Int)(c: Int)(d: Int) -&amp;gt; Int {
  return a + b + c + d
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;…so much cleaner than this? &lt;sup id=&quot;fnref:curried-function-example&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:curried-function-example&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;func fourChainedFunctions(a: Int) -&amp;gt; (Int -&amp;gt; (Int -&amp;gt; (Int -&amp;gt; Int))) {
  return { b in
    return { c in
      return { d in
        return a + b + c + d
      }
    }
  }
}

fourChainedFunctions(1)(2)(3)(4)
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Versions of these outlet/action assertion functions using the older, cleaner syntactic-sugary function currying can be reviewed on the &lt;a href=&quot;https://github.com/phatblat/CurriedOutletFunctions/blob/deprecated-syntax/CurriedOutletFunctionsTests/SpecFunctions.swift#L47&quot;&gt;&lt;code&gt;deprecated-syntax&lt;/code&gt;&lt;/a&gt; tag of the example repo.&lt;/p&gt;

&lt;p&gt;Apple, you can take my sweet curry, but you’ll never take my Sriracha.&lt;/p&gt;

&lt;center&gt;
&lt;img src=&quot;/images/sriracha-clip-on-bag.jpg&quot; width=&quot;400&quot; alt=&quot;&apos;Small Sriracha bottle attached to messenger bag&apos;&quot; title=&quot;Sriracha2Go&quot; /&gt;
&lt;/center&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h4 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h4&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:curry-func&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;As I’ve learned from @aligatr :crocodile: &lt;a href=&quot;#fnref:curry-func&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:action-test&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This bit of UIKit magic :sparkles: is from @qcoding’s &lt;a href=&quot;http://stackoverflow.com/questions/18699524/is-it-possible-to-test-ibaction&quot;&gt;post on Stack Overflow&lt;/a&gt; for how to test IBActions. &lt;a href=&quot;#fnref:action-test&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:quick&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;These tests are run using the &lt;a href=&quot;https://github.com/Quick/Quick&quot;&gt;Quick :stuck_out_tongue_winking_eye: testing framework&lt;/a&gt;. &lt;a href=&quot;#fnref:quick&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:swift3&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Note that function currying isn’t going away, only the nice shorthand (sweet :lollipop:) syntax is. &lt;a href=&quot;#fnref:swift3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:curried-function-example&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Borrowed with :heart: from the &lt;strong&gt;Almighty Kraken&lt;/strong&gt; :octopus: &lt;a href=&quot;http://krakendev.io/blog/hipster-swift#currying&quot;&gt;http://krakendev.io/blog/hipster-swift#currying&lt;/a&gt; &lt;a href=&quot;#fnref:curried-function-example&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Fri, 29 Apr 2016 13:39:19 -0600</pubDate>
        <link>https://phatbl.at/2016/04/29/testing-iboutlets-and-ibactions-with-curried-functions-in-swift.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/04/29/testing-iboutlets-and-ibactions-with-curried-functions-in-swift.html</guid>
        
        <category>swift,</category>
        
        <category>interface-builder,</category>
        
        <category>testing,</category>
        
        <category>function-currying,</category>
        
        <category>quick,</category>
        
        <category>nimble</category>
        
        
      </item>
    
      <item>
        <title>Mac Server Setup: Step 1</title>
        <description>&lt;p&gt;By default, Macs are designed to be user machines. While they are very easy to set up as servers, a few of the standard settings are not ideal for hosting services.&lt;/p&gt;

&lt;p&gt;If you are planning on using a Mac as a server - that is, you expect it to be running services indefinitely - there are some settings you should check on &lt;em&gt;first&lt;/em&gt;, before you are remote and having issues.&lt;/p&gt;

&lt;h2 id=&quot;energy-saver&quot;&gt;Energy Saver&lt;/h2&gt;

&lt;p&gt;Launch System Preferences and navigate to the Energy Saver pane. Change these settings:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Computer Sleep: Never&lt;/li&gt;
  &lt;li&gt;Display Sleep: Never&lt;/li&gt;
  &lt;li&gt;disable “Put hard disks to sleep when possible”&lt;/li&gt;
  &lt;li&gt;enable &lt;strong&gt;“Start up automatically after a power failure”&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/mac-server-setup-energysaver.jpg&quot; alt=&quot;&quot; title=&quot;Energy Saver system preferences pane&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is a screenshot from my Mac mini which @macminicolo was kind enough to set up like this for me.&lt;/p&gt;

&lt;h2 id=&quot;reading-values-from-the-command-line&quot;&gt;Reading Values from the Command Line&lt;/h2&gt;

&lt;p&gt;The values behind the Energy Saver preferences pane appear to be stored in User Defaults and can be read with the following command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;defaults read /Library/Preferences/SystemConfiguration/com.apple.PowerManagement
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The “Automatic Restart On Power Loss” key is the most important.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;{
    ActivePowerProfiles =      {
        &amp;quot;AC Power&amp;quot; = &amp;quot;-1&amp;quot;;
    };
    &amp;quot;Custom Profile&amp;quot; =     {
        &amp;quot;AC Power&amp;quot; =         {
            &amp;quot;AutoPowerOff Delay&amp;quot; = 14400;
            &amp;quot;AutoPowerOff Enabled&amp;quot; = 1;
            &amp;quot;Automatic Restart On Power Loss&amp;quot; = 1;
            DarkWakeBackgroundTasks = 0;
            &amp;quot;Disk Sleep Timer&amp;quot; = 0;
            &amp;quot;Display Sleep Timer&amp;quot; = 0;
            &amp;quot;Hibernate File&amp;quot; = &amp;quot;/var/vm/sleepimage&amp;quot;;
            &amp;quot;Hibernate Mode&amp;quot; = 0;
            PrioritizeNetworkReachabilityOverSleep = 0;
            &amp;quot;Sleep On Power Button&amp;quot; = 1;
            &amp;quot;Standby Delay&amp;quot; = 4200;
            &amp;quot;Standby Enabled&amp;quot; = 1;
            &amp;quot;System Sleep Timer&amp;quot; = 0;
            TTYSPreventSleep = 1;
            &amp;quot;Wake On LAN&amp;quot; = 1;
        };
        Defaults = 1;
    };
}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Because of the way these settings are stored, they are difficult to set using the &lt;code&gt;defaults&lt;/code&gt; command, which requires passing a plist file in order to set a tree of key-value pairs such as the above “Custom Profile” entry. The danger with doing this is that many values are set or unset in one step and these values will likely change through the years as OS X evolves.&lt;/p&gt;

&lt;h2 id=&quot;changing-values-from-the-command-line&quot;&gt;Changing Values from the Command Line&lt;/h2&gt;

&lt;p&gt;A better approach for manipulating these values from the command line is to use the &lt;code&gt;pmset&lt;/code&gt; command. This utility can be used to read the current Energy Saver values (read them all with &lt;code&gt;pmset -g&lt;/code&gt;, but uses shorter key aliases than defaults. The pmset keys are mostly space-free for easier typing on the command line.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;pmset -g
Active Profiles:
AC Power                -1* Currently in use:
 standby              1
 Sleep On Power Button 1
 womp                 1
 autorestart          1
 hibernatefile        /var/vm/sleepimage
 powernap             0
 networkoversleep     0
 disksleep            0
 sleep                0
 autopoweroffdelay    14400
 hibernatemode        0
 autopoweroff         1
 ttyskeepawake        1
 displaysleep         0
 standbydelay         4200
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;tldr&quot;&gt;TL;DR&lt;/h3&gt;

&lt;p&gt;These are the values you will always want to change when setting up a Mac server:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;sudo pmset -c sleep 0
sudo pmset -c displaysleep 0
sudo pmset -c disksleep 0
sudo pmset -c autorestart 1
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.neglectedpotential.com/2012/12/mac-mini-servers-a-cautionary-tale/&quot;&gt;Mac mini Servers: A Cautionary Tale&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.tekrevue.com/tip/mac-start-up-automatically-after-a-power-failure&quot;&gt;How and Why to Tell Your Mac to Start Up Automatically After a Power Failure&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://support.apple.com/kb/PH21704?viewlocale=en_US&amp;amp;locale=en_US&quot;&gt;Energy Saver preferences&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pmset.1.html&quot;&gt;pmset(1) Mac OS X Manual Page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sun, 10 Jan 2016 19:49:36 -0700</pubDate>
        <link>https://phatbl.at/2016/01/10/mac-server-setup.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/01/10/mac-server-setup.html</guid>
        
        <category>server,</category>
        
        <category>energy-saver,</category>
        
        <category>defaults,</category>
        
        <category>pmset</category>
        
        
      </item>
    
      <item>
        <title>The Accident</title>
        <description>&lt;p&gt;On Friday, November 20, 2015 I was walking home from work, but I never made it there. It was a cold night here in Colorado, about 20 degrees Fahrenheit (-6 Celsius), and a tiny amount of snow had fallen before I left the office. Not enough to stick, but the ground was wet, as were windshields.&lt;/p&gt;

&lt;p&gt;I left the office about 5:30pm, put on my new H7 headphones, started playing some drum ‘n bass and reset my &lt;a href=&quot;http://www.amazon.com/Komelon-ML1212-Meter-Man-4-Inch-Measuring/dp/B001QTVXVY/ref=lp_3753421_1_3?s=hi&amp;amp;ie=UTF8&amp;amp;qid=1452141522&amp;amp;sr=1-3&quot;&gt;measuring wheel&lt;/a&gt; to get an accurate distance of the trip I was embarking on. &lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;Just a block from the office is a major road with 3 lanes of traffic going each way. The street lights are notoriously long and even I get impatient waiting for the walk sign to come on. Pressing the pedestrian cross button gave the familiar beep-boop confirmation sound that it had sensed the touch of my gloved hand, but I pressed it 2 more times anyway for good measure.&lt;/p&gt;

&lt;p&gt;That night it was typical rush hour, but this late in the year (after Daylight Savings Time ends) it’s dark by the time I’m walking home. The clouds cut off even the hint of sunlight from the already-set sun. Only the streetlights and the headlights of hundreds of cars going by were illuminating the world right now.&lt;/p&gt;

&lt;p&gt;The green left arrow light came on and two lanes of cars turned left across the crosswalk ahead of me. I was enjoying my music but turned the volume down a bit so that I could hear the traffic around me. I would have taken them off, but the headphones were keeping my ears warm since I had forgotten to bring my hat to work. I was sure glad I had worn my long, warm wool jacket today as it was also keeping me warm that cold, wintery night.&lt;/p&gt;

&lt;p&gt;After what seemed like an eternity, the “white walking guy” sign lit up and I proceeded to enter the crosswalk, rolling my measuring wheel ahead of me. Soon after I passed the median, I heard a car approaching to my right. This was not unusual at all. Cars often sneak out into the lane waiting for me to finish crossing, hoping to occupy space in case the light changes while they are waiting. Or, maybe they are hoping I will run out of their way. On this day, I looked to my right to see the headlights of an SUV and the next thing I knew, I was on the ground and the right side of my hip hurt worse than I’ve ever felt in my life.&lt;/p&gt;

&lt;p&gt;It only took me a second to realize what had happened. The car had not stopped in time and had hit me. What was disorienting is that I couldn’t remember the impact. The intense pain was also disorienting. After a few more seconds, I realized that I couldn’t see anything and I think I opened my eyes. I saw the sidewalk on the far side of the road that I had been walking towards, but it was further up the road than the intersection corner. Later, I figured out I had been carried a full car length on the hood and then thrown another car length, 10 meters or so in total.&lt;/p&gt;

&lt;p&gt;Everything around me was lit up as I was in the path of traffic with several pairs of headlights shining on me. The closest of which was the car that hit me. I saw my headphones lying on the wet pavement about 2 meters from me. I heard people talking and could hear that one man was on his mobile phone with emergency services. I tried to roll on my back but as I did so my right shoulder erupted with pain. I decided that rolling was a bad idea and stayed on my side, despite the pain in my hip.&lt;/p&gt;

&lt;p&gt;My wife was waiting for me to get home. We had exchanged texts before I left work. She had an appointment and I was going to watch our son. The only thing I could think about was that I was about to be taken to a hospital and wouldn’t make it home. I tried to move my right arm to reach the Apple Watch on my left wrist. I was reminded that moving my right arm was a bad idea. I hadn’t used “Hey Siri” enough yet to remember that I can just talk to my watch, but I was determined to contact my wife.&lt;/p&gt;

&lt;p&gt;I lifted my left hand to my mouth, bit down on the finger of my glove and pulled it off. Then I reached in my left coat pocket and pulled out my iPhone. I unlocked it with my thumbprint and then tried to launch the Messages app. At this point I noticed that both my hands were shaking violently. While it was cold out, I had been bundled up well, so this shaking was mostly due to shock. It took a lot of attempts to hack out a 3-word message as I kept hitting the wrong keys on the keyboard. Again, I forgot I can talk to these technologies. Years of typing with my thumb make that my go-to input mechanism.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/accident-messages.jpg&quot; alt=&quot;&quot; title=&quot;iOS Messages app showing &amp;quot;Hit by car&amp;quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Eventually, I managed to enter “Hit by car” and hit the Send button. I locked my phone, put it back in my coat pocket and put my glove back on. I knew she would know where I was because that intersection is the only busy one in my .7 mile (1 km) walk home from work. I’ve had at least 3 close encounters in the same spot but I’m determined to walk because I enjoy the fresh air and time to think. The regular exercise has had a dramatic effect on my health as I was mostly sedentary before.&lt;/p&gt;

&lt;p&gt;I eventually rolled onto my back. My whole right side hurt and I wanted to start assessing the damage. There didn’t appear to be any blood, everything was still attached, it just hurt.&lt;/p&gt;

&lt;p&gt;The intersection was completely jammed. Two snowplows had driven into the middle of the intersection and stopped all the traffic to protect me. I could see that a few people had gotten out of there cars from where I was laying. A couple people covered me with blankets to keep me warm. The man on the phone assured me that an ambulance was on its way.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/accident-scene.jpg&quot; alt=&quot;&quot; title=&quot;Picture of the scene of the accident&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After what seemed like only a couple minutes, a police office came over and asked if I was OK. I said “I don’t know, I’m in a lot of pain”. He asked me my name and the current date - both of which I could tell I got right because I didn’t hesitate in answering. I recited my wife’s phone number from memory (the only one besides my own I know by heart. Who memorizes numbers anymore?) and the officer called to notify her of the accident. I didn’t mention I had texted her for fear of “Oh, you’re good. I’ll just cancel that ambulance.” She was halfway to the scene with our son in the car and had to pull over to take the call.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You did good. Your head must be all right.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Only a minute or so later the paramedics arrived and helped me to stand up. I couldn’t put any weight on my right leg without almost passing out with pain. I couldn’t even move my right leg forward to take a step. They helped me onto a stretcher and wheeled me into the ambulance.&lt;/p&gt;

&lt;p&gt;One of the paramedics put in an IV and gave me some sort of pain killer. I was already glad that I wasn’t a.) dead, b.) unconscious or c.) paralyzed, so I was in a pretty good mood. That mood got better once the meds kicked in and I wasn’t in mind-numbing pain.&lt;/p&gt;

&lt;p&gt;The ambulance hadn’t even closed the doors yet when my wife and son appeared in front of me. I was so glad to see them. I told them I was OK and that I was sorry my wife was going to miss her appointment.&lt;/p&gt;

&lt;p&gt;We started driving to the nearest hospital with my family following behind in our car.&lt;/p&gt;

&lt;h1 id=&quot;emergency-room&quot;&gt;Emergency Room&lt;/h1&gt;

&lt;p&gt;My memory of the hospital is a bit blurry since I was on strong pain killers by then. I don’t remember taking off my clothes, but I was in a hospital gown, so that must have happened at some point. I remember I was starving but we weren’t sure if I was going to need surgery yet. I was hoping not so that I could eat something.&lt;/p&gt;

&lt;p&gt;I remember the X-Rays. Oh boy. That was painful. The X-Ray technicians offered to help me move around into the positions they needed, but since I barely knew what was hurt I wasn’t comfortable with them moving me around. My left arm and leg were fine, so I could use them to move my right appendages around.&lt;/p&gt;

&lt;p&gt;After the X-Rays were done the ER Doctor said I had a fractured humerus near my shoulder. They didn’t find anything wrong with my hip. They helped me put my arm into a sling.&lt;/p&gt;

&lt;h2 id=&quot;police-debrief&quot;&gt;Police Debrief&lt;/h2&gt;

&lt;p&gt;A police officer different than the one that asked me questions while I was lying in the road came to the ER to get my statement. He told me a lot of details about the accident that I didn’t know before. Like the snowplows that had blocked the road. He also relayed the driver’s story. She had been in the outer turn lane and another car had turned close behind me, blocking her view of me. My dark coat also didn’t help as she didn’t see me in enough time to react.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/accident-map.jpg&quot; alt=&quot;&quot; title=&quot;Map with arrows showing traffic crossing my walking path&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The officer also mentioned that they found two hand prints on the hood of the car. I guess I dropped the measuring wheel and put up my hands to catch myself before my head hit. I don’t remember doing this. Good thing I have quick reflexes!&lt;/p&gt;

&lt;p&gt;Apparently, no one but myself saw the walk sign. I’m not surprised since drivers don’t normally need to look at those, but it’s weird that I’m the only person who knows that I had the right-of-way.&lt;/p&gt;

&lt;p&gt;The police office ended up giving the driver a reckless driving ticket.&lt;/p&gt;

&lt;h2 id=&quot;discharge&quot;&gt;Discharge?&lt;/h2&gt;

&lt;p&gt;Eventually a young admin was sent in to discharge me. She asked me to stand and follow her. I thought she was crazy, but followed orders. I almost fell when I tried to put weight on my right leg again. I forgot that this didn’t go so well the first time. Being heavily medicated, I was trusting that these health professionals knew what they were doing.&lt;/p&gt;

&lt;p&gt;They decided to do a CAT scan of my pelvis. That was actually fun because I didn’t have to do anything but lay there and the two technicians were hilarious. “You made it to Trauma Bravo status!”. I asked what I had to do to make it to Trauma Alpha. “Oh, lose a limb or lots of blood”. I decided that I liked Trauma Bravo.&lt;/p&gt;

&lt;p&gt;The CAT scan revealed two fractures in the acetabulum of my pelvis. They were in the socket right above where the ball of the femur sits, so no wonder it hurt when I put weight on that leg.&lt;/p&gt;

&lt;p&gt;The doctor relayed the info that an Orthopedic surgeon had given over the phone: 50% of this type of injury requires surgery. I’ve had minor surgery before, but this news hit me hard. I assumed that it meant a much longer recovery period. Immediately I was overcome by intense nausea. A nurse gave me some anti-nausea medication that they give cancer patients. Man, that stuff worked like a charm. I minute later and I was back to my normal drugged-up, broken self.&lt;/p&gt;

&lt;p&gt;Once I was no longer about to hurl and it was clear I wasn’t having surgery that night, I finally ate.&lt;/p&gt;

&lt;p&gt;About 10:30pm they rolled me across the hospital in a wheelchair and checked me into a room.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I’m working on a walking app which uses either GPS or the device accelerometer (depending on whether the iPhone has a motion co-processor) to measure distance. To gauge accuracy, I’ve been measuring common walking routes to compare with the values the app produces. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Wed, 06 Jan 2016 23:11:05 -0700</pubDate>
        <link>https://phatbl.at/2016/01/06/accident.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/01/06/accident.html</guid>
        
        <category>personal</category>
        
        
      </item>
    
      <item>
        <title>Jekyll Twitter Plugin</title>
        <description>&lt;p&gt;One of the downsides to using Octopress over vanilla Jekyll when deploying a blog like this to GitHub Pages is that you have to explicitly generate your static site files. This is because Octopress deploys only the static site to GHP. A simple Jekyll site can actually push the markdown source and config files directly to GHP and let them generate the static site. This downside is more pronounced for me as I’m doing the vast majority of work on this blog from my iPad Pro, where I don’t have a ruby environment to run the octopress and jekyll commands.&lt;/p&gt;

&lt;p&gt;However, there is a big upside to this arrangement: you’re not limitated to the few &lt;a href=&quot;https://help.github.com/articles/using-jekyll-plugins-with-github-pages/&quot;&gt;Jekyll plugins&lt;/a&gt; that GHP supports! GHP is simply hosting the generated site and I can run anything I want on my Mac to do that generation.&lt;/p&gt;

&lt;p&gt;So, let’s check out some nifty plugins, shall we?&lt;/p&gt;

&lt;h1 id=&quot;embedded-tweets&quot;&gt;Embedded Tweets&lt;/h1&gt;

&lt;p&gt;In the spirit of markup free writing, I’d like to be able to reference a tweet by URL and have the content and formatting applied automatically. Luckily, there are plugins for this.&lt;/p&gt;

&lt;h2 id=&quot;jekyll-tweet-tag&quot;&gt;jekyll-tweet-tag&lt;/h2&gt;

&lt;p&gt;The first plugin that I found when looking for this functionality is the obsolete &lt;a href=&quot;https://github.com/scottwb/jekyll-tweet-tag&quot;&gt;jekyll-tweet-tag&lt;/a&gt;. Save yourself some time and don’t bother installing this since it doesn’t work with the current Twitter API.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;!-- https://stackoverflow.com/a/5866429/39207 --&gt;
&lt;div class=&quot;language-liquid highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;{% tweet https://twitter.com/DEVOPS_BORAT/statuses/159849628819402752 %}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;jekyll-twitter-plugin&quot;&gt;jekyll-twitter-plugin&lt;/h2&gt;

&lt;p&gt;Based on the tweet-tag plugin, the &lt;a href=&quot;https://github.com/rob-murray/jekyll-twitter-plugin&quot;&gt;jekyll-twitter-plugin&lt;/a&gt; provides the same functionality but has been updated to work with the newer Twitter API preconditions (authentication keys) and also is a proper ruby gem for easier installation and updates.&lt;/p&gt;

&lt;p&gt;The syntax is very similar:&lt;/p&gt;

&lt;div class=&quot;language-liquid highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;{% twitter https://twitter.com/DEVOPS_BORAT/statuses/159849628819402752 %}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;jekyll-twitter-plugin&quot;&gt;&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Best analogy I find so far for explain concept of ScrumMaster to new devops is Tooth Fairy.&lt;/p&gt;&amp;mdash; DevOps Borat (@DEVOPS_BORAT) &lt;a href=&quot;https://twitter.com/DEVOPS_BORAT/status/159849628819402752?ref_src=twsrc%5Etfw&quot;&gt;January 19, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;/div&gt;

&lt;h3 id=&quot;ad-blockers&quot;&gt;Ad Blockers&lt;/h3&gt;

&lt;p&gt;Note: if you’re blocking the “Twitter Button” tracker with a browser plugin like Ghostery, you won’t see the &lt;a href=&quot;https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started&quot;&gt;Twitter Card&lt;/a&gt; version of these embedded tweets with images and they will instead fall back to a text-only version.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ghostery-twitter-button.png&quot; alt=&quot;Ghostery Safari plugin showing Twitter tracker blocked&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;align--width&quot;&gt;align &amp;amp; width&lt;/h3&gt;

&lt;p&gt;There are a few formatting options, such as &lt;code&gt;align&lt;/code&gt; and &lt;code&gt;width&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-liquid highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;{% twitter https://twitter.com/DEVOPS_BORAT/statuses/159849628819402752 align=&apos;center&apos; width=&apos;220&apos; %}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;jekyll-twitter-plugin&quot;&gt;&lt;blockquote class=&quot;twitter-tweet&quot; align=&quot;center&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Best analogy I find so far for explain concept of ScrumMaster to new devops is Tooth Fairy.&lt;/p&gt;&amp;mdash; DevOps Borat (@DEVOPS_BORAT) &lt;a href=&quot;https://twitter.com/DEVOPS_BORAT/status/159849628819402752?ref_src=twsrc%5Etfw&quot;&gt;January 19, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;width&lt;/code&gt; parameter must be between 220 and 550 inclusive and seems to have no effect on the text-only rendering of the tweet.&lt;/p&gt;

&lt;h3 id=&quot;hide_media&quot;&gt;hide_media&lt;/h3&gt;

&lt;p&gt;This plugin will pass along any extra parameters like &lt;code&gt;hide_media&lt;/code&gt; to the &lt;a href=&quot;https://dev.twitter.com/rest/reference/get/statuses/oembed&quot;&gt;oembed API&lt;/a&gt; for further customization.&lt;/p&gt;

&lt;div class=&quot;language-liquid highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;{% twitter https://twitter.com/DEVOPS_BORAT/statuses/159849628819402752 hide_media=&apos;true&apos; %}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;jekyll-twitter-plugin&quot;&gt;&lt;blockquote class=&quot;twitter-tweet&quot; data-cards=&quot;hidden&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Best analogy I find so far for explain concept of ScrumMaster to new devops is Tooth Fairy.&lt;/p&gt;&amp;mdash; DevOps Borat (@DEVOPS_BORAT) &lt;a href=&quot;https://twitter.com/DEVOPS_BORAT/status/159849628819402752?ref_src=twsrc%5Etfw&quot;&gt;January 19, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;/div&gt;

&lt;p&gt;Text rendering of the tweet is unaffected by &lt;code&gt;hide_media&lt;/code&gt; because it only includes a link by default.&lt;/p&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Note: Since version 2.0.0 these Authentication &amp;amp; API keys are no longer needed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are two options for configuring this Twitter plugin with your authentication keys:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Add them to &lt;code&gt;_config.yml&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Define them as environment variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since I’m tracking my &lt;code&gt;_config.yml&lt;/code&gt; in git, shared publicly on GitHub, I’m opting for #2.&lt;/p&gt;

&lt;p&gt;The challenge with environment variables is making sure they are defined whenever you need to run the command that depends on them. A simple solution is to add them to your &lt;code&gt;.bash_profile&lt;/code&gt; or &lt;code&gt;.zshrc&lt;/code&gt;, but since I’m &lt;em&gt;also&lt;/em&gt; &lt;a href=&quot;https://github.com/phatblat/dotfiles/blob/main/.zshrc&quot;&gt;storing that on GitHub&lt;/a&gt;, I’m going to look for another option.&lt;/p&gt;

&lt;h2 id=&quot;env-file&quot;&gt;.env File&lt;/h2&gt;

&lt;p&gt;Here is a very simple untracked file based solution. I created an &lt;code&gt;.env&lt;/code&gt; file containing each environment variable on a separate line like so:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;TWITTER_CONSUMER_KEY=...
TWITTER_CONSUMER_SECRET=...
TWITTER_ACCESS_TOKEN=...
TWITTER_ACCESS_TOKEN_SECRET=...
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The values in this file are then loaded into the environment for the Jekyll process on the fly using the &lt;code&gt;env&lt;/code&gt; command.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;env $(cat .env | xargs) bundle exec jekyll serve
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is wrapped up neatly in a &lt;a href=&quot;https://github.com/phatblat/dotfiles/blob/main/.config/fish/functions/serve.fish#L10&quot;&gt;&lt;code&gt;serve&lt;/code&gt;&lt;/a&gt; alias so I don’t have to type (or remember) all that each time.&lt;/p&gt;

&lt;p&gt;One caveat is that this command now generates an error if there is not an &lt;code&gt;.env&lt;/code&gt; file in the current directory. I like that because I’m frequently in the wrong directory when I type &lt;code&gt;serve&lt;/code&gt; and Jekyll is happy to create &lt;code&gt;_site&lt;/code&gt; folders wherever I happen to be before blowing up in my face.&lt;/p&gt;

&lt;h2 id=&quot;export&quot;&gt;Export&lt;/h2&gt;

&lt;p&gt;Note that the above environment variables can be loaded into the shell using the builtin &lt;code&gt;export&lt;/code&gt; command instead of &lt;code&gt;env&lt;/code&gt;. That is fine for testing, but leaves them defined in the environment for any other process to read.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-coderay&quot;&gt;&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;echo $TWITTER_CONSUMER_KEY
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;I tend to forget about this sort of thing (it works, :shipit:!) and would rather limit the exposure of sensitive values to the exact scope that they are needed.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/rob-murray/jekyll-twitter-plugin&quot;&gt;https://github.com/rob-murray/jekyll-twitter-plugin&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://dev.twitter.com/rest/reference/get/statuses/oembed&quot;&gt;https://dev.twitter.com/rest/reference/get/statuses/oembed&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/19331497/set-environment-variables-from-file&quot;&gt;http://stackoverflow.com/questions/19331497/set-environment-variables-from-file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Tue, 05 Jan 2016 12:51:55 -0700</pubDate>
        <link>https://phatbl.at/2016/01/05/jekyll-twitter-plugin.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/01/05/jekyll-twitter-plugin.html</guid>
        
        
      </item>
    
      <item>
        <title>Jemoji</title>
        <description>&lt;p&gt;I was browsing the GitHub Pages docs when I came across the list of &lt;a href=&quot;https://help.github.com/articles/using-jekyll-plugins-with-github-pages&quot;&gt;Jekyll plugins&lt;/a&gt; that are supported. Following the install/config instructions, I gave them a whirl on some &lt;a href=&quot;https://github.com/octopress/octopress#new-draft&quot;&gt;draft posts&lt;/a&gt; and they all worked fabulously with Octopress 3.&lt;/p&gt;

&lt;p&gt;To really give &lt;a href=&quot;https://github.com/jekyll/jemoji&quot;&gt;Jemoji&lt;/a&gt; a good test, I copied the entire list of emoji codes from &lt;a href=&quot;http://www.emoji-cheat-sheet.com&quot;&gt;emoji-cheat-sheet.com&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;people&quot;&gt;People&lt;/h1&gt;

&lt;p&gt;:bowtie: :smile: :laughing: :blush: :smiley: :relaxed: :smirk: :heart_eyes: :kissing_heart: :kissing_closed_eyes: :flushed: :relieved: :satisfied: :grin: :wink: :stuck_out_tongue_winking_eye: :stuck_out_tongue_closed_eyes: :grinning: :kissing: :kissing_smiling_eyes: :stuck_out_tongue: :sleeping: :worried: :frowning: :anguished: :open_mouth: :grimacing: :confused: :hushed: :expressionless: :unamused: :sweat_smile: :sweat: :disappointed_relieved: :weary: :pensive: :disappointed: :confounded: :fearful: :cold_sweat: :persevere: :cry: :sob: :joy: :astonished: :scream: :neckbeard: :tired_face: :angry: :rage: :triumph: :sleepy: :yum: :mask: :sunglasses: :dizzy_face: :imp: :smiling_imp: :neutral_face: :no_mouth: :innocent: :alien: :yellow_heart: :blue_heart: :purple_heart: :heart: :green_heart: :broken_heart: :heartbeat: :heartpulse: :two_hearts: :revolving_hearts: :cupid: :sparkling_heart: :sparkles: :star: :star2: :dizzy: :boom: :collision: :anger: :exclamation: :question: :grey_exclamation: :grey_question: :zzz: :dash: :sweat_drops: :notes: :musical_note: :fire: :hankey: :poop: :shit: :+1: :thumbsup: :-1: :thumbsdown: :ok_hand: :punch: :facepunch: :fist: :v: :wave: :hand: :raised_hand: :open_hands: :point_up: :point_down: :point_left: :point_right: :raised_hands: :pray: :point_up_2: :clap: :muscle: :metal: :fu: :runner: :running: :couple: :family: :two_men_holding_hands: :two_women_holding_hands: :dancer: :dancers: :ok_woman: :no_good: :information_desk_person: :raising_hand: :bride_with_veil: :person_with_pouting_face: :person_frowning: :bow: :couplekiss: :couple_with_heart: :massage: :haircut: :nail_care: :boy: :girl: :woman: :man: :baby: :older_woman: :older_man: :person_with_blond_hair: :man_with_gua_pi_mao: :man_with_turban: :construction_worker: :cop: :angel: :princess: :smiley_cat: :smile_cat: :heart_eyes_cat: :kissing_cat: :smirk_cat: :scream_cat: :crying_cat_face: :joy_cat: :pouting_cat: :japanese_ogre: :japanese_goblin: :see_no_evil: :hear_no_evil: :speak_no_evil: :guardsman: :skull: :feet: :lips: :kiss: :droplet: :ear: :eyes: :nose: :tongue: :love_letter: :bust_in_silhouette: :busts_in_silhouette: :speech_balloon: :thought_balloon: :feelsgood: :finnadie: :goberserk: :godmode: :hurtrealbad: :rage1: :rage2: :rage3: :rage4: :suspect: :trollface:&lt;/p&gt;

&lt;h1 id=&quot;nature&quot;&gt;Nature&lt;/h1&gt;

&lt;p&gt;:sunny: :umbrella: :cloud: :snowflake: :snowman: :zap: :cyclone: :foggy: :ocean: :cat: :dog: :mouse: :hamster: :rabbit: :wolf: :frog: :tiger: :koala: :bear: :pig: :pig_nose: :cow: :boar: :monkey_face: :monkey: :horse: :racehorse: :camel: :sheep: :elephant: :panda_face: :snake: :bird: :baby_chick: :hatched_chick: :hatching_chick: :chicken: :penguin: :turtle: :bug: :honeybee: :ant: :beetle: :snail: :octopus: :tropical_fish: :fish: :whale: :whale2: :dolphin: :cow2: :ram: :rat: :water_buffalo: :tiger2: :rabbit2: :dragon: :goat: :rooster: :dog2: :pig2: :mouse2: :ox: :dragon_face: :blowfish: :crocodile: :dromedary_camel: :leopard: :cat2: :poodle: :paw_prints: :bouquet: :cherry_blossom: :tulip: :four_leaf_clover: :rose: :sunflower: :hibiscus: :maple_leaf: :leaves: :fallen_leaf: :herb: :mushroom: :cactus: :palm_tree: :evergreen_tree: :deciduous_tree: :chestnut: :seedling: :blossom: :ear_of_rice: :shell: :globe_with_meridians: :sun_with_face: :full_moon_with_face: :new_moon_with_face: :new_moon: :waxing_crescent_moon: :first_quarter_moon: :waxing_gibbous_moon: :full_moon: :waning_gibbous_moon: :last_quarter_moon: :waning_crescent_moon: :last_quarter_moon_with_face: :first_quarter_moon_with_face: :crescent_moon: :earth_africa: :earth_americas: :earth_asia: :volcano: :milky_way: :partly_sunny: :octocat: :squirrel:&lt;/p&gt;

&lt;h1 id=&quot;objects&quot;&gt;Objects&lt;/h1&gt;

&lt;p&gt;:bamboo: :gift_heart: :dolls: :school_satchel: :mortar_board: :flags: :fireworks: :sparkler: :wind_chime: :rice_scene: :jack_o_lantern: :ghost: :santa: :christmas_tree: :gift: :bell: :no_bell: :tanabata_tree: :tada: :confetti_ball: :balloon: :crystal_ball: :cd: :dvd: :floppy_disk: :camera: :video_camera: :movie_camera: :computer: :tv: :iphone: :phone: :telephone: :telephone_receiver: :pager: :fax: :minidisc: :vhs: :sound: :speaker: :mute: :loudspeaker: :mega: :hourglass: :hourglass_flowing_sand: :alarm_clock: :watch: :radio: :satellite: :loop: :mag: :mag_right: :unlock: :lock: :lock_with_ink_pen: :closed_lock_with_key: :key: :bulb: :flashlight: :high_brightness: :low_brightness: :electric_plug: :battery: :calling: :email: :mailbox: :postbox: :bath: :bathtub: :shower: :toilet: :wrench: :nut_and_bolt: :hammer: :seat: :moneybag: :yen: :dollar: :pound: :euro: :credit_card: :money_with_wings: :e-mail: :inbox_tray: :outbox_tray: :envelope: :incoming_envelope: :postal_horn: :mailbox_closed: :mailbox_with_mail: :mailbox_with_no_mail: :package: :door: :smoking: :bomb: :gun: :hocho: :pill: :syringe: :page_facing_up: :page_with_curl: :bookmark_tabs: :bar_chart: :chart_with_upwards_trend: :chart_with_downwards_trend: :scroll: :clipboard: :calendar: :date: :card_index: :file_folder: :open_file_folder: :scissors: :pushpin: :paperclip: :black_nib: :pencil2: :straight_ruler: :triangular_ruler: :closed_book: :green_book: :blue_book: :orange_book: :notebook: :notebook_with_decorative_cover: :ledger: :books: :bookmark: :name_badge: :microscope: :telescope: :newspaper: :football: :basketball: :soccer: :baseball: :tennis: :8ball: :rugby_football: :bowling: :golf: :mountain_bicyclist: :bicyclist: :horse_racing: :snowboarder: :swimmer: :surfer: :ski: :spades: :hearts: :clubs: :diamonds: :gem: :ring: :trophy: :musical_score: :musical_keyboard: :violin: :space_invader: :video_game: :black_joker: :flower_playing_cards: :game_die: :dart: :mahjong: :clapper: :memo: :pencil: :book: :art: :microphone: :headphones: :trumpet: :saxophone: :guitar: :shoe: :sandal: :high_heel: :lipstick: :boot: :shirt: :tshirt: :necktie: :womans_clothes: :dress: :running_shirt_with_sash: :jeans: :kimono: :bikini: :ribbon: :tophat: :crown: :womans_hat: :mans_shoe: :closed_umbrella: :briefcase: :handbag: :pouch: :purse: :eyeglasses: :fishing_pole_and_fish: :coffee: :tea: :sake: :baby_bottle: :beer: :beers: :cocktail: :tropical_drink: :wine_glass: :fork_and_knife: :pizza: :hamburger: :fries: :poultry_leg: :meat_on_bone: :spaghetti: :curry: :fried_shrimp: :bento: :sushi: :fish_cake: :rice_ball: :rice_cracker: :rice: :ramen: :stew: :oden: :dango: :egg: :bread: :doughnut: :custard: :icecream: :ice_cream: :shaved_ice: :birthday: :cake: :cookie: :chocolate_bar: :candy: :lollipop: :honey_pot: :apple: :green_apple: :tangerine: :lemon: :cherries: :grapes: :watermelon: :strawberry: :peach: :melon: :banana: :pear: :pineapple: :sweet_potato: :eggplant: :tomato: :corn:&lt;/p&gt;

&lt;h1 id=&quot;places&quot;&gt;Places&lt;/h1&gt;

&lt;p&gt;:house: :house_with_garden: :school: :office: :post_office: :hospital: :bank: :convenience_store: :love_hotel: :hotel: :wedding: :church: :department_store: :european_post_office: :city_sunrise: :city_sunset: :japanese_castle: :european_castle: :tent: :factory: :tokyo_tower: :japan: :mount_fuji: :sunrise_over_mountains: :sunrise: :stars: :statue_of_liberty: :bridge_at_night: :carousel_horse: :rainbow: :ferris_wheel: :fountain: :roller_coaster: :ship: :speedboat: :boat: :sailboat: :rowboat: :anchor: :rocket: :airplane: :helicopter: :steam_locomotive: :tram: :mountain_railway: :bike: :aerial_tramway: :suspension_railway: :mountain_cableway: :tractor: :blue_car: :oncoming_automobile: :car: :red_car: :taxi: :oncoming_taxi: :articulated_lorry: :bus: :oncoming_bus: :rotating_light: :police_car: :oncoming_police_car: :fire_engine: :ambulance: :minibus: :truck: :train: :station: :train2: :bullettrain_front: :bullettrain_side: :light_rail: :monorail: :railway_car: :trolleybus: :ticket: :fuelpump: :vertical_traffic_light: :traffic_light: :warning: :construction: :beginner: :atm: :slot_machine: :busstop: :barber: :hotsprings: :checkered_flag: :crossed_flags: :izakaya_lantern: :moyai: :circus_tent: :performing_arts: :round_pushpin: :triangular_flag_on_post: :jp: :kr: :cn: :us: :fr: :es: :it: :ru: :gb: :uk: :de:&lt;/p&gt;

&lt;h1 id=&quot;symbols&quot;&gt;Symbols&lt;/h1&gt;

&lt;p&gt;:one: :two: :three: :four: :five: :six: :seven: :eight: :nine: :keycap_ten: :1234: :zero: :hash: :symbols: :arrow_backward: :arrow_down: :arrow_forward: :arrow_left: :capital_abcd: :abcd: :abc: :arrow_lower_left: :arrow_lower_right: :arrow_right: :arrow_up: :arrow_upper_left: :arrow_upper_right: :arrow_double_down: :arrow_double_up: :arrow_down_small: :arrow_heading_down: :arrow_heading_up: :leftwards_arrow_with_hook: :arrow_right_hook: :left_right_arrow: :arrow_up_down: :arrow_up_small: :arrows_clockwise: :arrows_counterclockwise: :rewind: :fast_forward: :information_source: :ok: :twisted_rightwards_arrows: :repeat: :repeat_one: :new: :top: :up: :cool: :free: :ng: :cinema: :koko: :signal_strength: :u5272: :u5408: :u55b6: :u6307: :u6708: :u6709: :u6e80: :u7121: :u7533: :u7a7a: :u7981: :sa: :restroom: :mens: :womens: :baby_symbol: :no_smoking: :parking: :wheelchair: :metro: :baggage_claim: :accept: :wc: :potable_water: :put_litter_in_its_place: :secret: :congratulations: :m: :passport_control: :left_luggage: :customs: :ideograph_advantage: :cl: :sos: :id: :no_entry_sign: :underage: :no_mobile_phones: :do_not_litter: :non-potable_water: :no_bicycles: :no_pedestrians: :children_crossing: :no_entry: :eight_spoked_asterisk: :sparkle: :eight_pointed_black_star: :heart_decoration: :vs: :vibration_mode: :mobile_phone_off: :chart: :currency_exchange: :aries: :taurus: :gemini: :cancer: :leo: :virgo: :libra: :scorpius: :sagittarius: :capricorn: :aquarius: :pisces: :ophiuchus: :six_pointed_star: :negative_squared_cross_mark: :a: :b: :ab: :o2: :diamond_shape_with_a_dot_inside: :recycle: :end: :back: :on: :soon: :clock1: :clock130: :clock10: :clock1030: :clock11: :clock1130: :clock12: :clock1230: :clock2: :clock230: :clock3: :clock330: :clock4: :clock430: :clock5: :clock530: :clock6: :clock630: :clock7: :clock730: :clock8: :clock830: :clock9: :clock930: :heavy_dollar_sign: :copyright: :registered: :tm: :x: :heavy_exclamation_mark: :bangbang: :interrobang: :o: :heavy_multiplication_x: :heavy_plus_sign: :heavy_minus_sign: :heavy_division_sign: :white_flower: :100: :heavy_check_mark: :ballot_box_with_check: :radio_button: :link: :curly_loop: :wavy_dash: :part_alternation_mark: :trident: :black_small_square: :white_small_square: :black_medium_small_square: :white_medium_small_square: :black_medium_square: :white_medium_square: :black_large_square: :white_large_square: :white_check_mark: :black_square_button: :white_square_button: :black_circle: :white_circle: :red_circle: :large_blue_circle: :large_blue_diamond: :large_orange_diamond: :small_blue_diamond: :small_orange_diamond: :small_red_triangle: :small_red_triangle_down: :shipit:&lt;/p&gt;

&lt;p&gt;This pleases me :trollface:&lt;/p&gt;

&lt;p&gt;To see the &lt;strong&gt;:emoji_code:&lt;/strong&gt; for any of the above emoji, check the alt text on the image.&lt;/p&gt;
</description>
        <pubDate>Sun, 03 Jan 2016 21:29:17 -0700</pubDate>
        <link>https://phatbl.at/2016/01/03/jemoji.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/01/03/jemoji.html</guid>
        
        <category>jekyll,</category>
        
        <category>github-pages,</category>
        
        <category>emoji</category>
        
        
      </item>
    
      <item>
        <title>Radar: Apple Pencil Cannot Be Used for Any Screen Edge Swipe Gestures</title>
        <description>&lt;h1 id=&quot;rdar23839606&quot;&gt;&lt;a href=&quot;http://www.openradar.me/23839606&quot;&gt;rdar://23839606&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/meme-pencil.jpg&quot; alt=&quot;She asked if she could borrow my pencil, so I guess you could say things are getting pretty serious&quot; /&gt;&lt;/p&gt;

</description>
        <pubDate>Sun, 03 Jan 2016 15:05:13 -0700</pubDate>
        <link>https://phatbl.at/radars/2016/01/03/radar-apple-pencil-cannot-be-used-for-any-screen-edge-swipe-gestures.html</link>
        <guid isPermaLink="true">https://phatbl.at/radars/2016/01/03/radar-apple-pencil-cannot-be-used-for-any-screen-edge-swipe-gestures.html</guid>
        
        <category>radar,</category>
        
        <category>apple-pencil,</category>
        
        <category>ipad</category>
        
        
        <category>radars</category>
        
      </item>
    
      <item>
        <title>iPad Pro Mini-Review</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;This was originally posted on Facebook on 2015-12-01. It’s not a very detailed review as it was intended for my non-technical friends and family. Reposting here as the size comparison with the MacBook will probably be interesting to others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Talked with my dad earlier today and was raving to him how much I love the new iPad Pro. I’ve used every iPad since the original but this is the first one that has the potential to replace a laptop IMHO, at least for casual users or casual use by pro users. Case in point: it’s pretty much all I’ve been using for the last week and a half while I’ve been laid up at home recovering from my &lt;a href=&quot;/2016/01/06/accident.html&quot;&gt;accident&lt;/a&gt;. The only things I’ve broken out my MacBook for are for Xcode, a second set of browser tabs for some Black Friday and Cyber Monday shopping and to do some general maintenance on my development tools.&lt;/p&gt;

&lt;div class=&quot;jekyll-twitter-plugin&quot;&gt;&lt;blockquote class=&quot;twitter-tweet&quot; align=&quot;center&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;The iPro may be a REALLY BIG iPad, but it&amp;#39;s also a really light laptop, depending on how you look at it&lt;/p&gt;&amp;mdash; Ben Chatelain (@phatblat) &lt;a href=&quot;https://twitter.com/phatblat/status/674332881938833408?ref_src=twsrc%5Etfw&quot;&gt;December 8, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;/div&gt;

&lt;p&gt;So, what’s so great about this? It’s “just” a bigger iPad, right? That’s exactly why!&lt;/p&gt;

&lt;p&gt;I don’t even have my Apple Pencil or Smart Keyboard yet (both of which only work with the Pro), but this device finally makes sense because of the big screen.&lt;/p&gt;

&lt;h2 id=&quot;multiple-apps&quot;&gt;Multiple Apps&lt;/h2&gt;

&lt;p&gt;iOS 9 introduces a new Split View feature where you can have two apps onscreen at the same time. The last 3 pictures in this set show this in action. This is only fully supported on the &lt;a href=&quot;http://gadgets.ndtv.com/mobiles/features/ios-9-how-to-use-split-screen-multitasking-and-picture-in-picture-741244?site=classic&quot;&gt;iPad Pro, Air 2 and Mini 4&lt;/a&gt; right now. Developers do have to add Split View support to their apps, otherwise the 2nd app is only a temporary flyover (Apple calls Slide Over). Adding this support is trivial (took me 15 minutes to add it to a Kaiser app), but even Facebook hasn’t updated their app with support for this yet. Expect it to be added very soon.&lt;/p&gt;

&lt;h2 id=&quot;readability&quot;&gt;Readability&lt;/h2&gt;

&lt;p&gt;I use glasses to see a computer screen clearly and without eye strain, even on a laptop. This is because the distance to the screen is right between near sight and far sight. An iPad (or any mobile device) is held nearer to the eyes so I don’t need glasses. Where a device this big excels is that everything is bigger and more readable. The size is so big that I can pull up a photo full screen and show it to someone across the room.&lt;/p&gt;

&lt;p&gt;OK, enough selling, here are the pics. The smaller device is the 2015 12” MacBook. The gray silicone iPad Pro cover is top quality with plush microfiber inside.&lt;/p&gt;

&lt;h1 id=&quot;pictures&quot;&gt;Pictures&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-01.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Glorious display. Also, this setup has a blue bias.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-02.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Not very exciting to look at, but I’m expecting this case to take the wear so the iPad can stay shiny.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-03.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So soft&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-04.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Silicone case on left, naked iPad Pro on right&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-05.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Huge 12.9” screen&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-06.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I can’t wait until my Smart Keyboard arrives so I’ll have a stand+keyboard. I paired a normal Apple Bluetooth keyboard with the Pro earlier for some emails, but had to prop the iPad up on a book to use at a desk.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-07.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;2 pound (.9 kg) laptop, 1.5 pound (.68 kg) iPad&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-08.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The smaller one can be used to make apps for the bigger one. The odd shine is a cheap skin to prevent scratches.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-09.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Safari on the left and Notes app on the right.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-10.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Safari on the left and Mail on right composing an email with the split in the middle.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ipro-review-11.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Again, Safari on the left and Mail on the right composing and email, but with the split moved to the right. Mail adapts to more of the UI on the iPhone.&lt;/p&gt;
</description>
        <pubDate>Sun, 03 Jan 2016 08:53:53 -0700</pubDate>
        <link>https://phatbl.at/2016/01/03/ipro-review.html</link>
        <guid isPermaLink="true">https://phatbl.at/2016/01/03/ipro-review.html</guid>
        
        <category>ipad,</category>
        
        <category>review</category>
        
        
      </item>
    
  </channel>
</rss>
