Skip to content

Instantly share code, notes, and snippets.

View FredrikSjoberg's full-sized avatar

Fredrik Sjöberg FredrikSjoberg

  • Volvo Cars
  • Sweden
View GitHub Profile
-11800 : unknown
-11801 : outOfMemory
-11803 : sessionNotRunning
-11804 : deviceAlreadyUsedByAnotherSession
-11805 : noDataCaptured
-11806 : sessionConfigurationChanged
-11807 : diskFull
-11808 : deviceWasDisconnected
-11809 : mediaChanged
-11810 : maximumDurationReached
@FredrikSjoberg
FredrikSjoberg / AVErrorCodeDescriptions.swift
Last active May 24, 2018 09:14
AVError.code descriptions
func errorAndCode(code: AVError.Code) -> (Int, String) {
return (code.rawValue, describeAVError(code: code))
}
func describeAVError(code: AVError.Code) -> String {
switch code {
case .unknown: return "unknown"
case .outOfMemory: return "outOfMemory"
case .sessionNotRunning: return "sessionNotRunning"
case .deviceAlreadyUsedByAnotherSession: return "deviceAlreadyUsedByAnotherSession"
//: Playground - noun: a place where people can play
import Foundation
import GameplayKit
struct Game: Sequence, IteratorProtocol {
// Should return a random Int between 0-Param, ie 0<=x<3
let random: (Int) -> Int
let doors: Int = 3
extension CGPoint : Hashable {
func distance(point: CGPoint) -> Float {
let dx = Float(x - point.x)
let dy = Float(y - point.y)
return sqrt((dx * dx) + (dy * dy))
}
public var hashValue: Int {
// iOS Swift Game Development Cookbook
// https://books.google.se/books?id=QQY_CQAAQBAJ&pg=PA304&lpg=PA304&dq=swift+CGpoint+hashvalue&source=bl&ots=1hp2Fph274&sig=LvT36RXAmNcr8Ethwrmpt1ynMjY&hl=sv&sa=X&ved=0CCoQ6AEwAWoVChMIu9mc4IrnxgIVxXxyCh3CSwSU#v=onepage&q=swift%20CGpoint%20hashvalue&f=false
return x.hashValue << 32 ^ y.hashValue
@FredrikSjoberg
FredrikSjoberg / RGBtoHSV.swift
Last active April 11, 2024 11:22
Color space conversion between RGB and HSV
// https://www.cs.rit.edu/~ncs/color/t_convert.html
struct RGB {
// Percent
let r: Float // [0,1]
let g: Float // [0,1]
let b: Float // [0,1]
static func hsv(r: Float, g: Float, b: Float) -> HSV {
let min = r < g ? (r < b ? r : b) : (g < b ? g : b)
let max = r > g ? (r > b ? r : b) : (g > b ? g : b)