Sadly, Senator @jiminhofe knows nothing of what he speaks. http://nymag.com/daily/intelligencer/2015/02/senator-refutes-climate-change-with-snowball.html
Author Archives: Norm
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!
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.
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
Building an iPhone 6
As most of the world saw yesterday, Apple announced two new iPhones, the iPhone 6 and the iPhone 6 Plus, both of which are larger than the previous iPhone 5/s/c models. If history repeats itself, Apple’s initial supply of these phones will be tight and so pre-ordering your phone this Friday (September 12, 2014) is your best bet at getting your hands on one. [Note: If you are just upgrading your phone, I highly recommend purchasing it via the Apple Store app on your current iPhone!] This of course, presents a bit of a dilemma, which iPhone to choose? This is especially true for those of us with smaller hands (the current iPhone 5s is pushing the limits of what I can reach with one hand). To help myself and now you out, I’ve created mockups of the iPhone 6 and 6 Plus so you can determine if the 6 Plus really feels like holding an iPad mini to your head.
NB: These are strictly my mockups based on information available online, I don’t have any inside knowledge!
With a little patience, a pair of scissors, and some Scotch tape, you should be good to go. Here are png files for each phone. Just click on them, download to your computer (right click and save to Downloads), and print them out.
Enjoy!
iPhone 6
iPhone 6 Plus
My First Bracket
Have you fallen prey to Warren Buffet’s Billion Dollar Bracket Challenge? I have. Despite knowing the (approximate) odds of winning, it was enough impetus for me to register and fill out a bracket. I’m not a “fantasy” player for any sport but have to say I was incredibly impressed with Yahoo’s bracket website. Brilliantly done guys! The big winner here is, of course, Warren Buffet and Quicken Loans. Brilliant advertising with basically zero probability of having to payout. Math experts may be arguing about the exact odds of picking a perfect bracket but all agree it’s 1 in BILLIONS (a rough calculation puts my bracket at 1 in 7.5 billion). I read ESPN has had over 30 million brackets filled out online over the years and have never seen a perfect one.
Well, enough chit chat. Here’s my bracket:
Let March Madness begin!
Norm’s VDOT Calculator
The Silicon Valley Triathlon Club (SVTC) used to have an old Perl based VDOT calculator. If you don’t know what VDOT is, take a look here or at Jack Daniel’s wiki page. The SVTC calculator has not worked for a long time, so I managed to get the code behind the calculator and rewrote its functionality in PHP. It’s not pretty to look at (yet) but you can find my version of the VDOT calculator here. I’ll see if I can figure out a way to integrate it into this blog/site more cleanly.
Let me know if you have any questions or comments.
Update: I have managed to integrate my VDOT calculator into this blog, so I’m updated the link above to point to its new location. I created a new page for it so it also has a menu item that points directly to the page.