Skip to content

Instantly share code, notes, and snippets.

@kylehowells
kylehowells / SystemBlurExamplesViewController.swift
Created April 3, 2022 19:50
Examples of the different UIBlurEffect styles available in iOS
import UIKit
import PhotosUI
class SystemBlurExamplesViewController: UIViewController, PHPickerViewControllerDelegate {
// MARK: - Setup View
override func loadView() {
self.view = SystemBlurExamplesView()
}

Getting a streamable link is done by the client.

You basically need to send the service a detailed list of the type of media you can play, and it will give you a transcode URL to call if it thinks you need transcoding in order to play this file.

If you don't and can play the file directly it won't give you a transcode URL.

POST <server_address>/Items/<item_id>/PlaybackInfo?UserId=<current_user_id>
import Foundation
protocol ExampleObserver:AnyObject {
func methodThatDoesSomething()
}
class Example: NSObject {
@kylehowells
kylehowells / UIColor+Interpolate.swift
Created July 17, 2021 22:09
Swift Playground showing 3 different ways to interpolate between colors
import UIKit
extension UIColor {
func interpolateRGBColorTo(_ end: UIColor, fraction: CGFloat) -> UIColor? {
let f = min(max(0, fraction), 1)
guard let c1 = self.cgColor.components, let c2 = end.cgColor.components else { return nil }
let r: CGFloat = CGFloat(c1[0] + (c2[0] - c1[0]) * f)
extension UIColor {
func kh_renderImage() -> UIImage? {
let size = CGSize(width:1, height: 1)
return UIGraphicsImageRenderer(size: size).image(actions: { (rendererContext) in
let context = UIGraphicsGetCurrentContext()
self.setFill()
context?.fill(CGRect(origin: .zero, size: size))
})
}
@kylehowells
kylehowells / ViewController+Starscream.swift
Created August 3, 2020 02:49
Proof on concept WebSocket application comparing the built in NSURLSessionWebSocketTask and the Starscream WebSocket library on Github
//
// ViewController.swift
// WebSocket Echo
//
// Created by Kyle Howells on 02/08/2020.
// Copyright © 2020 Kyle Howells. All rights reserved.
//
import UIKit
import Starscream
@kylehowells
kylehowells / max_size.swift
Created July 9, 2020 03:03
Get the maximum supported Metal texture size for the current device on iOS or macOS.
import SceneKit
import CoreGraphics
static func getMaxImageWidth() -> Int {
let device = MTLCreateSystemDefaultDevice()!
// According to the Metal Feature Set Tables there are only two supported maximum resolutions
// 16384px for macs and the latest iOS devices
// 8192px for the older iOS devices
// Older Apple devices used to be limited to 4,096, 2,048 or even 1,024, but are no longer supported
@kylehowells
kylehowells / locales.txt
Last active June 30, 2020 21:38
[SFSpeechRecognizer supportedLocales] on macOS 10.15.5
Arabic (Saudi Arabia) (ar-SA)
Catalan (Spain) (ca-ES)
Czech (Czechia) (cs-CZ)
Danish (Denmark) (da-DK)
German (Austria) (de-AT)
German (Switzerland) (de-CH)
@kylehowells
kylehowells / Speedo.swift
Created June 28, 2020 17:37
Scifi Style Speedometer Concept in SwiftUI
import SwiftUI
struct ContentView: View {
let backgroundGradient = Gradient(colors: [
Color(red: 65.0/255.0, green: 65.0/255.0, blue: 84.0/255.0, opacity: 1.0),
Color(red: 20.0/255.0, green: 20.0/255.0, blue: 24.0/255.0, opacity: 1.0)
])
let blueGradient = Gradient(colors: [
@kylehowells
kylehowells / GradientText.swift
Created June 27, 2020 22:58
SwiftUI gradient text fill
struct GradientText: View {
@State var text: String
@State var gradient:LinearGradient = LinearGradient(
gradient: Gradient(colors: [.white, .gray]),
startPoint: .top,
endPoint: .bottom
)
var body: some View {