Skip to content

Instantly share code, notes, and snippets.

@garmstro
garmstro / NSString+StringExtensions.h
Created November 9, 2015 22:29
NSString Extensions
//
// NSString+StringExtensions.h
// StringFunctions
//
// Created by Geoff Armstrong on 10/29/15.
// Copyright © 2015 Geoff Armstrong. All rights reserved.
//
#ifndef NSString_StringExtensions_h
#define NSString_StringExtensions_h
@garmstro
garmstro / NSNumber+NSNumberExtensions.h
Created November 9, 2015 22:27
NSNumber Extensions
//
// NSInteger+NSIntegerExtensions.h
// IntegerFunctions
//
// Created by Geoff Armstrong on 10/30/15.
// Copyright © 2015 Geoff Armstrong. All rights reserved.
//
#ifndef NSNumber_NSNumberExtensions_h
#define NSNumber_NSNumberExtensions_h
@garmstro
garmstro / GSABinaryTree.h
Created November 9, 2015 22:25
Objective C Initial Binary Tree Implementation
//
// GSABinaryTree.h
// BinaryTree
//
// Created by Geoff Armstrong on 11/3/15.
// Copyright © 2015 Geoff Armstrong. All rights reserved.
//
#ifndef GSABinaryTree_h
#define GSABinaryTree_h
@garmstro
garmstro / NSArray+NSArrayExtensions.h
Created November 9, 2015 22:21
NSArray Extensions
//
// NSArray+NSArrayExtensions.h
// ArrayFunctions
//
// Created by Geoff Armstrong on 11/4/15.
// Copyright © 2015 Geoff Armstrong. All rights reserved.
//
#ifndef NSArray_NSArrayExtensions_h
#define NSArray_NSArrayExtensions_h
/**
Calculates the pitch angle for the device based on it's orientation from the Quaternion
- parameter quat: The Quaternary from CMMotionManager.attitude
- returns: pitch The pitch of the device, scaled so that vertical is 0 degrees
*/
private func pitchFromQuaternion(quat: CMQuaternion) -> Double {
// http://stackoverflow.com/questions/9478630/get-pitch-yaw-roll-from-a-cmrotationmatrix/18764368#18764368
//let degRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z))
/**
Calculate the x-pixel offset for an angle
- parameter angle: The viewing angle for the object
- returns: xOffset CGFloat for the x location of the object on the screen
*/
private func getXPixelOffset(angle: Double) -> CGFloat {
var xOffset = CGFloat(0.0)
/**
Calculate the x-pixel offset for an angle using perspective projection
http://stackoverflow.com/questions/16619104/perspective-projection-in-android-in-an-augmented-reality-application
- parameter angle: The viewing angle for the object
- returns: xOffset CGFloat for the x location of the object on the screen
*/
private func getXPerspectiveOffset(angle: Double) -> CGFloat {
/**
Calculate initial compass bearing between two locations
- parameter fromLocation: Source Location
- parameter toLocation: Destination Location
- returns: bearing (CLLocationDirection)
*/
private func bearingFromLocation(fromLocation: CLLocation, toLocation: CLLocation) -> CLLocationDirection {
@garmstro
garmstro / verticalSlider.swift
Created May 18, 2015 18:17
Programmatically add a vertical slider to a ViewController and adjust for orientation changes
//
// ViewController.swift
//
// Created by Geoff Armstrong on 3/31/15.
// Copyright (c) 2015 Geoff Armstrong. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@garmstro
garmstro / JsonHandler.swift
Created May 17, 2015 01:11
JSON File Reader
//
// JsonHandler.swift
//
// Created by Geoff Armstrong on 4/6/15.
// Copyright (c) 2015 Geoff Armstrong. All rights reserved.
//
import Foundation
import UIKit