- imagineric : interactive design & technology

Swift 3: Distance between two CGPoints

Here it is in Swift 3, it’s a little different. I tried to use hypotf but it didn’t like CGFloat subtraction.


iOS to macOS: Reading keyboard input

Coming from iOS go macOS, I wanted to read keyboard input in my macOS application. Not from a textfield but rather from the window itself. I thought this would be an easy task. After some trial and error, Googling, and then some StackOverflow fishing, I managed to get this to work. It wasn’t exactly straightforward for me to get but now that I did, I’d like to share the code that makes it work.

In my ViewController.swift file, I set up a few delegate callbacks

In my viewDidLoad, I added event monitoring (which eluded me for some time).

I then added keyUp and keyDown functions for the NSViewController itself.

I have a class variable (keyIsDown) which prevents keyboard repeats to flood the methods. Set that to false at the start.

This works a treat – and I didn’t have to subclass NSView, do anything in AppDelegate, etc. It’s clean, legible, and it does exactly what you’d expect it to do. This is for a single windowed application.

Protocol/delegates in Swift 3.0

I declare this day a fine day having discovered non-Objective-C protocols! No more @objc protocol usage. Now it’s as simple as something like this:

And then in implementation

This is a really simple example, but it works and seems cleaner to me in Swift.

Shaking a macOS Window

There may come a time when you’d like to shake a macOS application’s window (or one of them) to reinforce an event. In my case, I am creating a macOS application that serves as a conduit to control aspects of a user experience. It communicates with an iOS application which serves as a kind of remote control for the macOS application. And settings are synchronized back and forth. It’s pretty cherry.

macOS Sierra and iOS 10 using Swift 3 are quite similar. I know enough about iOS development to make myself a drunken lumberjack in a glade of birch trees – swinging wildly hoping to hit things. Anyway, I am using MultipeerConnectivity framework for the communication discovery and data transfer (at a top-level explanation). When a connection is made (the iOS app advertises), I turn a little grey dot into a green one to show this state. When a disconnection is made, I turn it back to grey.

However, this might not be enough. I could play a disconnection tone (and I still might), but I wanted to shake the window to let someone know, “Hey! I lost a connection.” This sets expectations and it’s a cool effect I wanted to try out.

I have an extension that will do this, written for Swift 3. It’s implementation is a little different than for previous versions of Swift. Here is the extension. The Cocoa import is because I keep separate extension swift files instead of in-lining everything into a view controller, etc. This keeps things cleaner and a little easier for me and others to find.

I certainly hope that you enjoy it.

Quick & Easy JavaScript/PHP CMS

by Eric Dolecki 0 Comments

I needed to create a website where I could update multiple pages worth of content remotely. It’s a travel blog. I could use WordPress to do this out of the gate, but I wanted to get away from the whole commoditized theme look and feel. Something where I have more control without customizing a lot.

So I created a site structure with multiple pages (one per travel day – ahead of time). Each of those PHP pages has a PHP include for the guts of the content for that day. For example

Easy peasy. That PHP file contains HTML of the contents. So for each day there is a file to include. Each one could contain a lot of information, so I didn’t want to do run down the dynamic population route too far.

So that part is easy. What about editing/adding content to the PHP files remotely? Enter an admin page.

The admin page has a drop-down menu of all the PHP include files. The first one it automatically loaded into a textarea control. You can select different pages and load them into the textarea with some JavaScript.

Easy too. However JavaScript can’t write back to the files, so we POST the text to a PHP script page and that writes to the file (filename and contents are posted).

Easy again. The PHP script takes the variables and uses them to save the data. So with a little PHP and a little JavaScript, we have a CMS system. It’s not robust but rather lightweight. And I have full control over all aspects of how things look, feel, and operate.

Something to consider to avoid the continued WordPress onslaught.


Bose QC 35 versus Blue Microphone Mo-Fi

by Eric Dolecki 0 Comments


I’m lucky enough to have access to both products, the Bose QuietComfort 35 and the Blue Microphone Mo-Fi. The Mo-Fi currently can be purchased from Amazon for $318.99 (discounted from $349.99) and the Bose for $349.99 (no discount offered).

Screen Shot 2016-09-02 at 1.45.50 PMI was told to try out the Mo-Fi by BT himself (Brian Transeau) as he swears by them. That was about a year ago. So I sought the Mo-Fi out and I’ve been using them on and off, with QC25s and then QC35s. A note: The QC35s are wireless BT, the Mo-Fi are wired with a built-in amplifier with three states: off, on, and on+ for some bass boost.

I listen to an eclectic set of music. New Age (Andreas Vollenweider), Electronic (BT, Trentmøller, Sasha, Zomby, etc.), Rock (Rush, Queensrÿche, Afghan Whigs, Led Zeppelin, etc.), Heavy Metal (Megadeth, Iron Maiden, old Metallica, etc.) In no situation has the Mo-Fi bested the Bose sound, even with the on+ setting activated.

Countless hours of listening, I get far more clarity from the Mo-Fi, regardless of what BT thinks of them. I am not taking into account the comfort of either headphone. However, the Bose are 1,025 times more comfortable in my opinion. And far lighter.

It might just be my ears, as the Mo-Fi are indeed highly rated. And BT loves them. He’s a brand ambassador on the Blue website. I just don’t get it. I’ve tried to as the headphones are unique in their appearance. And I like the idea of a powered amplifier (that also saves my phone from some power draw). My audio files are good/great quality. Not listening to vinyl with them –  and perhaps that’s the rub?

I may never know. Putting the Bose back on 🙂

Truefitt & Hill 1805 vs St. James Sandalwood & Bergamot shaving cream

For years I have tried various shaving creams, expensive and cheap – except for XPEC since that’s around $80 a tub. I’ve narrowed it down to 1805 as my favorite go to shaving cream. Taylor of Old Bond Street easily a number two (just about any scent but Eton College it’s amazing).

I read a few wet shavers think that St. James makes a trip notch cream so I had to try it. Then compare it to 1805. 

The scent is not something I can honestly say I love. Let’s get to lathering. It’s a soft cream in a glass jar which is a nice touch since TH come in PVC tubs. Lathering is more difficult but not incredibly so. It definitely takes more water to get going but works up well given a lurker more effort. It’s slick and pleasant and hold up well in the bowl. Using my silvertip brush I can easily get a few passes. The shave is good. 

1805 worthy? Not a chance. 1805 is a dream to work with and the scent is immaculate and a bit more masculine. It’s more slick as well. And I could easily go for six passes which would be asking for trouble. Three is my limit and with Feathers I can get away with two without second thought. 

Is it TOOBS worthy? Again no. I would place it behind. It’s not unpleasant save the aroma, but it lacks the character and ease. Placing it solidly at number three. It’s not cheap and thus this will be my first and my last glass container of the stuff. 

Mount Everest Base Camp Trek

by Eric Dolecki 0 Comments

I’ve been bitten by the Mount Everest bug – just the very idea of it – for a number of years. I worked on a sherpa-inspired work project a many, many years ago and that got me initially interested in the notion of an ascent. Knowing full well that my athletic years have passed me by, my last shot at something would be something like a base camp trek.

Everest base camp sits at 5,364m/17,589ft above sea level. Kala Putter sits at 5,550m/18,208ft above sea level. No small feet – if you pardon the pun. There is 50% of the oxygen at base camp as there is at sea level. Extra oxygen makes you warmer, so 30ºF at sea level is going to feel far colder at altitude.

I’ve found an excellent resource (Everest FAQ) online that documents actually Everest summiting and gear, but much of that should apply to a base camp trek – especially for someone like me who knows absolutely squat about any of it. In fact, it’s a little daft to do such a thing. But I’m not getting older, and the window to physical stuff like this becomes more remote with each calendar year.

I’ve discovered that REI offers a trek as well as Mountain Ram Adventures. Mountain Ram is shorter by about 7 days and thus it’s far cheaper and also probably more accommodating in regards to available calendar. REI is 19 days long, MRA is 12 days long. I wonder if that means MRA is more grueling in terms of acclimatization and miles covered per day.

Another one is ActiveAdventures. They offer a base camp trek too – 19 days and $4,000 per person.

Here is the REI itinerary:

  • Day 2: Explore Swayambunath Temple, Boudhanath Temple, Durbar Square, and more.
  • Day 3: Fly to Lukla and hike through colorful villages to Phakding.
  • Day 4: Hike through fields and villages from Phakding to Namche Bazaar.
  • Day 5: Day hike for our first views of Everest, then return to Namche Bazaar.
  • Day 6: Ascend to the village of Phortse Tenga through rhododendron forest.
  • Day 7: Half-day ascent to visit Pangboche’s impressive monastery.
  • Day 8: Hike to Dingboche, the highest permanent Sherpa village in the Khumbu.
  • Day 9: Day hike to remote monastic caves and views of Makalu.
  • Day 10: Traverse the Pheriche Valley and ascend past the Khumbu glacier.
  • Day 11: Depending on weather, climb Kala Patar or hike to Everest Base Camp.
  • Day 12: Depending on our previous day, climb Kala Patar or hike to Base Camp.
  • Day 13: Cross Pheriche Pass before arriving at Tengboche Monastery.
  • Day 14: Trek to Namche Bazaar, with views of Everest, Lhotse, and Ama Dablam.
  • Day 15: Leave Namche Bazaar and descend to Phakding Village.
  • Day 16: Hike to Lukla and enjoy a final night in a comfortable lodge.
  • Day 17: Return flight from Lukla to Kathmandu, weather permitting.
  • Day 18: Free day to explore more highlights of the Kathmandu Valley.
  • Days 19: Our Everest Base Camp trekking adventure ends today in Kathmandu.

And the MRA itinerary:

  • Day 01: Early morning fly to Lukla and then trek to Phakding.
  • Day 02: Phakding to Namche (3450 m)
  • Day 03: Namche rest for acclimatization.
  • Day 04: Namche to Tengbuche (4 to 5 hours)
  • Day 05: Tengbuche to Dingbuche (5 to 6 hours)
  • Day 06: Rest at Dingboche for further acclimatization
  • Day 07: Dingbuche to Lobuche (4 to 5 hours)
  • Day 08: Lobuche to Gorakshep – EBC- Gorakshep. (5 to 10 hours)
  • Day 09: Gorakshep to Kalapatther and down to Pheriche 6 hours trek.
  • Day 10: Pheriche to Namche (6 hours of walking down)
  • Day 11: Namche to Lukla (7 hours of walking down)
  • Day 12: Lukla to Kathmandu (early morning flight, 30 minutes)

The highlights of the 19 days AA:

  • Trek to Everest Base Camp
  • Explore the colourful and vibrant city of Kathmandu
  • Visit Namche Bazaar Hike through Sherpa villages
  • View Mt Everest from Kala Patthar
  • Visit Swayambhunath “Monkey” Temple

Here is a lovely video documentary made recently (MRA).R

Here is a slideshow of images from the REI (I believe).

And finally one from active adventures

So begins the thought progress of all of this.

Gerlach Enigma update

Incredible. What an awesome beater. The only thing I don not like about this watch is the concentric rings on the sub dials, because they reflect a lot of light which sometimes makes it look like there is a scratch or two on the domed sapphire. There never is, and I’ve banged this watch against door handles galore. It’s a great watch and as a bonus I wear my Polish pride on my wrist.