Skip to content

Instantly share code, notes, and snippets.

View scottmkroberts's full-sized avatar

Scott Roberts scottmkroberts

  • Advance Labs
  • Peterborough, UK
View GitHub Profile
@scottmkroberts
scottmkroberts / fizzBuzz
Last active August 29, 2015 14:02
Fizz Buzz in Siwft
for i in 1...100{
let divisbleBy3 = i%3
let divisbleBy5 = i%5
if divisbleBy3 == 0 && divisbleBy5 == 0{ // no remainder
println("fizz buzz")
}else if divisbleBy3 == 0{
println("fizz")
}else if divisbleBy5 == 0{
println("buzz")
@scottmkroberts
scottmkroberts / AuthChecks
Last active August 29, 2015 14:04
checkAuthorisationForCharacteristicType
-(BOOL)checkAuthorisationForCharacteristicType:(HKCharacteristicType *)characteristicType{
HKAuthorizationStatus authStatus = [self.store authorizationStatusForType:characteristicType];
if(authStatus == HKAuthorizationStatusSharingAuthorized){
return YES;
}else{
return NO;
}
@scottmkroberts
scottmkroberts / HealthKitFormatter
Created July 25, 2014 15:56
Part of my HealthKitFormatter Class
//
// HealthKitFormatter.m
// HealthKitExample
//
// Created by Scott Roberts on 24/07/2014.
// Copyright (c) 2014 Scottr. All rights reserved.
//
#import "HealthKitFormatter.h"
@scottmkroberts
scottmkroberts / money
Created November 27, 2014 19:40
UK Currency
// Playground - noun: a place where people can play
import UIKit
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
numberFormatter.formatterBehavior = NSNumberFormatterBehavior.Behavior10_4
numberFormatter.currencyCode = "GBP"
numberFormatter.generatesDecimalNumbers = true
numberFormatter.locale = NSLocale(localeIdentifier: "en_UK")
NSString *string = [NSString alloc] initWithStringFormat:@"%i", 3];
@scottmkroberts
scottmkroberts / Buzz Fizz
Created November 7, 2011 20:16
Objective C - test 1
#import <Foundation/Foundation.h>
/* Test I had to do, Took me way to long so thought I would draft it up in objective c
basically getting the remainder using the % modular type.
loop through to 100, if number is divisible by 3 print buzz if its divisible by 5 print fizz and if its both print buzz fizz. Else just print the number.
*/
int main(int argc, char *argv[]) {
@scottmkroberts
scottmkroberts / UIBezierPathRoundedCorner
Created February 20, 2013 22:34
Multiple Rounded corners with UIBezierPath using the | character
// Create the path (with only the top-left corner rounded)
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_categoryColorView.bounds
byRoundingCorners:UIRectCornerTopLeft |
UIRectCornerBottomLeft
cornerRadii:CGSizeMake(10.0, 10.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayerTop = [CAShapeLayer layer];
maskLayerTop.frame = _categoryColorView.bounds;
@scottmkroberts
scottmkroberts / UITableViewSnippet
Last active December 14, 2015 00:39
Just UITableView Snippet (because i can never be bothered to type this all out)
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
}
@scottmkroberts
scottmkroberts / CoreDataDefaultCodeSnippet
Last active December 14, 2015 00:39
Core Data Code (for when I quickly want to manually add Core Data to a project)
//-- NOTE: Do not forget to add Framework
//-- Extra Header Code
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
@scottmkroberts
scottmkroberts / SegueSnippet
Created February 21, 2013 19:20
Pushing Segue Snippet
[self performSegueWithIdentifier:@"id" sender:self];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"id"]) {
// Do stuff.
}
}