Pi Day!!!

As you probably have seen, tomorrow, March 14, 2015, when written using the standard US (short) notation 3/14/15, spells out the first 5 digits of Pi. As it turns out, you can go even further down the Pi “number” hole. Here are a couple of good references:

Vox has a good (layperson) explanation of Pi Day
http://www.vox.com/2015/3/13/8205807/pi-day

Jeff Rosenthal has a detailed explanation of the Pi Instant
http://probability.ca/jeff/writing/PiInstant.html

You can also find your birthday “spelled out” WITHIN the digits of Pi using this cool Wolfram site!  Here is mine:

Vernal Equinox – March 20, 2015

The 2015 Vernal Equinox, which marks the first day of Spring for Northern Hemisphere dwellers, is almost upon us. This is the (one of 2) point(s) in the Earth’s orbit when the tilt of its axis (e.g. the North Pole) is neither pointing toward nor away from the Sun. In this situation, virtually all parts of the Earth receive (approximately) equal amounts of day and night (12 hours each). It’s also the point at which the increasing amount daylight (or night-time in the case of the Autumn Equinox) is at a maximum! Here are a few links if you’d like to learn more about equinoxes:

Wikipedia

Time and Date

The Old Farmer’s Almanac

McLaren 675LT vs Tesla P85D

I’m an F1 fan and can’t wait for the 2015 season to start at Melbourne in a couple of weeks. However, I don’t consider myself a “car guy”. I don’t fantasize about cool/fast cars, etc. but I did find this announcement by McLaren interesting.

The McLaren 675LT Takes Off at Geneva Motor Show, Fast and Street-Legal

Specifically, this section:

It has a 666bhp V8 engine with a 0 to 62-mile-per-hour sprint time of 2.9 seconds. Top speed is 205 mph. You’ll be hard-pressed to find anything street-legal that can beat that time, apart from a Bugatti. (Pricing has yet to be announced on this, but Car+Driver estimates it’ll be $345,000. I agree it’ll likely be a heck of a lot less than the $2-million-plus Bugatti Veyron.)

I found that comment interesting, given this article from November 3, 2014 (the fact of which has been widely publicized since) about Tesla’s “Insane” mode on the new P85D. There have been recent rumors that suggest the P85D’s 0-60 time could drop to 2.9s after an upcoming firmware update. Don’t get me wrong, the $120,000 price tag of the Tesla P85D seems ridiculous to me but pales in comparison to $345,000 for the P1. I know, comparing apples to oranges but if you are looking purely at acceleration…

Since I’m trying to write about science, here are a few graphs for you. This first one comes from a reddit.com posting and the second comes from dragtimes.com. The second graph is a V-T graph, so the slopes are acceleration, which you can see are pretty much linear (which is remarkable for a car). Insane mode provides a horizontal acceleration (also shown on the graph) in the neighborhood of 1g! Wow!

Tesla Model S Power and Torque

 

Tesla-P85D-Insane-vs-Sport-Mode-Graph

Creating a Transparent Modal UIViewController in iOS 8

I’ve just started to scratch the surface of all the cool things iOS 8 can do, so much to learn! One of my apps presents a modal view controller that asks the user to select a date from a custom calendar view I built. The app displays photos and this modal vc is presented over an image, so I wanted the modal vc to be (semi) transparent, so the image could be seen behind it. I scoured the web but there seemed to be a lot of conflicting ideas out there and none of them worked for me. I happened to stumble upon a/the solution on my own, while poking around Attributes Inspector.

Select the (modal’s – i.e. the one you want to be transparent) view controller from your storyboard and then click on the Attributes Inspector. As you can see in the screen shot below, there are Transition Style and Presentation options now available. The Transition Style is just what you expect it is and for Presentation, you want to select Over Current Context. Viola! Crazy simple.

Attributes Inspector

I’d be interested to hear what has worked for you in iOS 7, although backward compatibility is quickly becoming less interesting to me.

How To Convert HTML to NSAttributedString

I’m not sure what the best practice is these days when displaying HTML content in your app. It seems you can either put it into a UIWebView or you can, as of iOS 7, convert it to an NSAttributedString and put it into a UILabel, UITextField, etc. I have been leaning toward the latter recently and thought I’d post the 2 lines of code required to make that happen.

NSAttributedString *stringWithHTMLAttributes = [[NSAttributedString alloc] initWithData:[self.htmlText dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:nil];

self.htmlLabel.attributedText = stringWithHTMLAttributes;

The above code assumes you have HTML stored in an NSString variable called “self.htmlText” and a UILabel called htmlLabel and that your encoding is UTF8.

Let me know if you have any questions or if there is a better practice I’m not aware of.

How to Convert an ISO8601 Date in iOS

I still find working with dates in iOS a little tricky. There is always a new format to deal with and it’s all about getting the identifiers for the format just right! I recently ran into ISO8601 and hope the bit of code below is of some use.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
NSDate *date = [dateFormatter dateFromString:self.releaseDate];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
self.dateString = [dateFormatter stringFromDate:date];

You can, of course, pick any other date format style (instead of Long) as the output. As always, let me know if you have any questions.

Parsing Strava’s GPX File in PHP

I love Strava! However, as with all tracking sites, Strava doesn’t always provide the exact window I want into my data. I’ve been thinking about building an app that allows me to manipulate the specific data I’m interested in but to do that, one has to get the data first. Given that, I’ve been playing around with parsing Strava GPX files. I’ve been looking at Garmin GPX and FIT files as well, but the Strava ones seem the easiest to work with.

The challenge I had with the Strava GPX file was getting at the data in the extensions: temperature (atemp), heart rate (hr) and Cadence (cad) data. It took me a few hours to figure out how to parse those values (I’m not very good at XML, namespaces, etc.), so I wanted to post this bit of PHP code to hopefully save others some time!

foreach($stravaData->trk->trkseg->children() as $trkpts) {
    $dataPoint->trkpt = $i;
    $dataPoint->latitude = $trkpts['lat'];
    $dataPoint->longitude = $trkpts['lon'];
    $dataPoint->elevation = $trkpts->ele;
    $dataPoint->time = $trkpts->time;
    $dataPoint->temp = $trkpts->extensions->children('gpxtpx', true)->TrackPointExtension->atemp;
    $dataPoint->hr = $trkpts->extensions->children('gpxtpx', true)->TrackPointExtension->hr;
    $dataPoint->cad = $trkpts->extensions->children('gpxtpx', true)->TrackPointExtensi
 on->cad;
    ...
}

The above code assumes you have created a “dataPoint” class to store the relevant Strava data (trackpoint number, latitude, longitude, elevation, time, temp, hr, cad, … you may have others like power). Let me know if you have any questions.

Handoff in iOS 8 and Yosemite (Beta)

I’ve been trying to get Handoff, one of of iOS 8’s Continuity features, to work since the betas of iOS 8 and Yosemite were available on the Apple Developer Site with very limited success. Now that iOS 8 is GM, it seems to finally work. Here are the steps I took to get it working.

First off, you need to make sure all of your devices are logged into the same Apple ID account. If you tap on the Settings app and scroll down to iCloud, iOS 8 now shows you which Apple ID you are logged in with, very handy. Same for OS X Yosemite, go to Settings > iCloud and on the left side beneath your photo is the active account. This was the case for me, so I moved on to the next step.

The main problem I had was my Mac and my iPad were not showing up in my iPhone’s Bluetooth settings panel. Restarting both my iPad and iPhone, as well as toggling Bluetooth off then on seemed to solve this issue. Note: It can take your iPad or iPhone a LONG time to see other devices (e.g. Mac, iPad, or iPhone) via Bluetooth, so you have to be patient.

Once both devices were restarted, all my other devices started to show up in the Bluetooth settings area. If this isn’t the case, try restarting again. Once you “see” them in Bluetooth settings, Handoff will work.

Of course, Handoff only works with apps that support this feature, such as Maps, Messages, Mail, Safari, Calendar, etc. I’ve already seen third party apps supporting it, so make sure to update (ideally via auto update) the apps on your devices. Also, I’ve only been able to activate Handoff (for iOS devices) from the Lock Screen. Maybe this is how it works. I really like how OS X Yosemite handles it, with a new icon on the left end of your Dock. If you know how to activate Handoff other than from the Lock Screen, I’m all ears!!!

[In iOS 8, a “grey” icon appears in the bottom left corner of the lock screen of your device. Swipe up (and possibly enter your passcode) to active Handoff.]

Finally, there still seems to be a few glitches. I noticed my iPhone or iPad didn’t always show the icon for the app I had activated on my Mac. For example, I’d bring Mail to the foreground, check my iPhone’s lock screen and see the little (grey) Mail icon in the lower left. Then I’d switch to Safari on my Mac. Sometimes the iPhone would update the icon to Safari, sometimes it wouldn’t. However, I’m sure this feature will just get better in future updates. For now, I’ve been able to get it work between Mac and iOS devices and between multiple iOS devices.

Not rocket science but hopefully this helps.

Norm