This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String), parserError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" | |
case .apiError(let reason), .parserError(let reason): | |
return reason | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Shared | |
// | |
// Created by Costantino Pistagna on 25/03/21. | |
// | |
import SwiftUI | |
struct ContentView: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func validate<T: Codable>(_ validator: @escaping (T) -> Bool) -> (T) -> Bool { | |
return { input in | |
return validator(input) | |
} | |
} | |
enum StringValidator: CustomStringConvertible { | |
case isNotEmpty | |
case lengthIn(ClosedRange<Int>) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prompt_char { | |
if [ $UID -eq 0 ]; then echo "#"; else echo $; fi | |
} | |
PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[cyan]%}%n@)%m:%{$fg_bold[green]%}%(!.%~.%1~)%{$fg_bold[yellow]%} $(git_prompt_info)%{$fg_bold[cyan]%}$(prompt_char)%{$reset_color%} ' | |
ZSH_THEME_GIT_PROMPT_PREFIX="(" | |
ZSH_THEME_GIT_PROMPT_SUFFIX=") " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
enum APIError: Error, LocalizedError { | |
case unknownError | |
case unknownURL | |
case unknownData | |
case parserError(reason: String) | |
case apiError(reason: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String), parserError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension View { | |
func iff(_ condition: Bool, _ modifier: (Self) -> AnyView) -> AnyView { | |
if condition { | |
return modifier(self).eraseToAnyView() | |
} | |
return eraseToAnyView() | |
} | |
func some<Value>(_ optional: Value?, modifier: (Value, Self) -> AnyView) -> some View { | |
guard let value = optional else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIImage { | |
/** | |
Resizes the image to width x height and converts it to an RGB CVPixelBuffer. | |
*/ | |
public func pixelBuffer(width: Int, height: Int) -> CVPixelBuffer? { | |
var maybePixelBuffer: CVPixelBuffer? | |
let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, | |
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Date { | |
typealias FormattedString = (DateFormatter) -> String | |
func formatted(by format: String) -> FormattedString { | |
return { formatter in | |
formatter.dateFormat = format | |
return formatter.string(from: self) | |
} |
NewerOlder