Skip to content

Instantly share code, notes, and snippets.

View mattrobmattrob's full-sized avatar
🐢

Matt Robinson mattrobmattrob

🐢
View GitHub Profile
@mattrobmattrob
mattrobmattrob / fix_line_endings.sh
Created July 7, 2015 20:39
Add correct line endings to make Git diff work better
#!/bin/bash
FILES=~/Path/To/Folder/With/Files
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f stores current file name.
ed -s $f <<< w
done
@mattrobmattrob
mattrobmattrob / Slow iOS Startup.md
Last active November 2, 2016 01:46
Summary and investigation into the reasons that start up could be for an iOS application.

Links

@mattrobmattrob
mattrobmattrob / HealthKit_Permission.m
Created July 12, 2017 18:55
Strava Apple Watch Blog - HealthKit
/// After using `requestAuthorizationToShareTypes:readTypes:completion:`
- (BOOL)hasRequestedHeartRateAuthorization
{
return (HKAuthorizationStatusNotDetermined != [HKHealthStore authorizationStatusForType:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]]);
}
- (void)requestHeartRateAuthorizationWithCompletion:(void (^)(BOOL succes, NSError *error))completion
{
NSSet *readTypes = [NSSet setWithObject:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]];
[self.store requestAuthorizationToShareTypes:nil readTypes:readTypes completion:^(BOOL success, NSError *error){
@mattrobmattrob
mattrobmattrob / MotionFitness_Permission.m
Created July 12, 2017 18:56
Strava Apple Watch Blog - Motion & Fitness
- (void)hasMotionAndFitnessAuthorizationWithCompletion:(void (^)(BOOL authorized, NSError * _Nullable error))completion
{
__weak typeof(self) weakSelf = self;
// request samples within the past week. we want to be relatively sure that we'll get a quick response from this query since it can
// block the critical path. if we were to request updates starting now, the user would have to walk around enough to trigger an update before
// the completion block would be executed.
NSDate *lastWeekDate = [[NSDate date] dateByAddingTimeInterval:-1209600.0];
[self.authorizationPedometer startPedometerUpdatesFromDate:lastWeekDate
withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
@mattrobmattrob
mattrobmattrob / Location_Permission.m
Created July 12, 2017 18:57
Strava Apple Watch Blog - Location
- (void)requestWhenInUseAuthorization
{
[CLLocationManager requestWhenInUseAuthorization];
}
+ (BOOL)locationServicesAvailable
{
BOOL result = [CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] >= kCLAuthorizationStatusAuthorizedAlways;
return result;
}
@mattrobmattrob
mattrobmattrob / Notification_Permission.m
Created July 12, 2017 18:58
Strava Apple Watch Blog - Notifications
__block BOOL areNotificationsAuthorized = NO;
[UNUserNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
areNotificationsAuthorized = UNAuthorizationStatusAuthorized == settings.authorizationStatus;
}];
@mattrobmattrob
mattrobmattrob / SCNBox_Different_Color_Sides.swift
Created August 31, 2017 19:34
Swift transposed version of a different color approach on all sides of a `SCNBox` (https://stackoverflow.com/a/27509866/856336)
/// Generate `SCNMaterial` that is the specified color
func material(withColor color : UIColor) -> SCNMaterial {
let material = SCNMaterial();
material.diffuse.contents = color
material.locksAmbientWithDiffuse = true
return material
}
let greenMaterial = material(withColor: UIColor.green)
let redMaterial = material(withColor: UIColor.red)
final class BubbleView: UIView {
override func draw(_ rect: CGRect) { ... }
}
extension BubbleView {
func drawBubble(in bubbleBounds: CGRect, bubbleColor: UIColor) {
// 1.
guard let context = UIGraphicsGetCurrentContext() else { return }
// 2.
context.setFillColor(bubbleColor.cgColor)
// 3.
context.fillEllipse(in: bounds)
}
}
extension BubbleView {
/// Draws a set of stripes across the view up from bottom left
/// to top right at a 45 degree angle. The stripes will be
/// `stripeWidth` wide and have `stripeWidth` between them.
func drawStripes(in bubbleBounds: CGRect,
stripeColor: UIColor,
stripeWidth: CGFloat) {...}
}
final class BubbleView: UIView {