Skip to content

Instantly share code, notes, and snippets.

View danielpi's full-sized avatar

Daniel Pink danielpi

View GitHub Profile
@danielpi
danielpi / Date Extension.swift
Created February 19, 2018 06:14
Gives you a way to create a formatted date string in one line
extension Date {
func usingFormat(_ format: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format
return dateFormatter.string(from: self)
}
}
// Example
// Date().usingFormat("yyyy-MM-dd'T'HHmmss")
// "2018-02-19T16105"
Inside Roof Basement
02661 02554 01313
02671 02565 01334
02673 02566 01313
02669 02567 01317
02673 02565 01335
02671 02568 01364
02673 02565 01375
02673 02565 01389
02674 02567 01384
@danielpi
danielpi / OSTypedEnum.swift
Created March 27, 2017 13:29
Extension to AVCaptureVideoDataOutput and an enum to represent OSType CVPixelFormatType data
extension AVCaptureVideoDataOutput {
var availableVideoCVPixelFormatTypedEnums: [OSTypedEnum] {
let availablePixelFormatDescriptions: Array<OSType> = self.availableVideoCVPixelFormatTypes as! Array<OSType>
let availablePixelFormats: Array<OSTypedEnum> = availablePixelFormatDescriptions.map { OSTypedEnum(rawValue: $0)! }
return availablePixelFormats
}
}
enum OSTypedEnum: OSType {
case monochrome1 = 1
@danielpi
danielpi / Distance.swift
Last active January 12, 2016 13:19
My response to http://ericasadun.com/2016/01/11/make-this-swift-er-coordinate-distances/ Note I'm really just experimenting with a concept of encoding a calculations units into Swifts type system rather than actually suggesting that this is the best solution to the original problem. However this does have the advantage of taking care of conversi…
import Cocoa
public protocol Unit: CustomStringConvertible {
var value: Double { get set }
var baseSymbol: String { get }
init(value: Double)
}
public extension Unit {
@danielpi
danielpi / Matrify.swift
Created December 2, 2015 04:34
Turn a list into a matrix
//: # Matrify
//:
//: Turn a list into a matrix
import Cocoa
let a = [1,2,3,4,5,6,7,8,9]
func matrify(list: [Int], rowLength: Int) -> [[Int]] {
@danielpi
danielpi / MathematicsProtocol
Created April 9, 2015 22:25
A protocol to use when you want to write a generic function that can accept Ints, Floats or Doubles.
protocol MathematicsProtocol: Equatable, Comparable, IntegerLiteralConvertible {
init(_ value: Int)
init(_ value: Float)
init(_ value: Double)
func +(lhs: Self, rhs: Self) -> Self
func -(lhs: Self, rhs: Self) -> Self
func * (lhs: Self, rhs: Self) -> Self
func / (lhs: Self, rhs: Self) -> Self
}