Skip to content

Instantly share code, notes, and snippets.

@msepcot
msepcot / MarathonCalculator.swift
Created March 3, 2021 01:04
Exploring different marathon race time calculations.
import Foundation
class Calculator {
class Constants {
static let kilometersPerMile = 1.60934
static let metersPerMile = 1609.34
}
enum Distance: Double { // rawValue in miles
case marathon = 26.21875
@msepcot
msepcot / HealthKitPRSearch.swift
Created March 3, 2021 01:07
Search HealthKit data for running PRs.
//
// ViewController.swift
// WatchAndLearn
//
// Created by Michael Sepcot on 9/18/19.
// Copyright © 2019 Michael Sepcot. All rights reserved.
//
import UIKit
import HealthKit
@msepcot
msepcot / AgeGradeCalculator.swift
Last active April 6, 2021 03:16
A port of the Runner's World Age Grading Calculator to Swift
import Foundation
enum Gender {
case male, female // no non-binary data :/
}
enum Distance {
case fiveKm, sixKm, fourMi, eightKm, fiveM, tenKm, twelveKm, fifteenKm, tenMi, twentyKm, halfMarathon, twentyFiveKm, thirtyKm, marathon, fiftyKm, fiftyMi, oneHundredKm, oneHundredFiftyKm, oneHundredMi, twoHundredKm
}
@msepcot
msepcot / RandomAccessCollection+BinarySearch.swift
Created November 6, 2021 00:15
Binary Search extension on RandomAccessCollection that lets the caller do the compare on each element.
public extension RandomAccessCollection {
func binarySearch(comparing: (Element) -> ComparisonResult) -> Element? {
var lowerBound = startIndex
var upperBound = endIndex
while lowerBound < upperBound {
let size = distance(from: lowerBound, to: upperBound)
let midIndex = index(lowerBound, offsetBy: size / 2)
switch comparing(self[midIndex]) {
case .orderedSame: