Skip to content

Instantly share code, notes, and snippets.

View romiroma's full-sized avatar
🗿
Focusing

Roman Andrykevych romiroma

🗿
Focusing
  • Kyiv, Ukraine
View GitHub Profile
@romiroma
romiroma / SampleBufferDelegate.swift
Last active September 9, 2021 08:04
Downscale CVPixelBuffer with metal
import AVFoundation
import MetalPerformanceShaders
final class SamplebufferDelegate: NSObject, MTLTextureSource, AVCaptureVideoDataOutputSampleBufferDelegate {
var consumer: MTLTextureConsumer?
private let device: MTLDevice = MTLCreateSystemDefaultDevice()!
private var textureCache: CVMetalTextureCache!
private let texAttributes = [kCVMetalTextureUsage as String: [MTLTextureUsage.shaderRead],
kCVMetalTextureStorageMode as String: [MTLStorageMode.shared]] as CFDictionary
@romiroma
romiroma / NonContinuousRange.swift
Last active February 22, 2021 14:15
NonContinuousRange - merging ClosedRange<T: Strideable>
struct NonContinuousRange<T: Strideable> where T.Stride: SignedInteger {
private(set) var ranges: [ClosedRange<T>] = []
mutating func insert(range newRange: ClosedRange<T>) {
guard !ranges.isEmpty else {
ranges.append(newRange)
return
}
@romiroma
romiroma / Tappable-SwiftUI.swift
Created October 31, 2020 06:06
Tappable Text in SwiftUI
import Foundation
import SwiftUI
struct TappableColoredText: View {
enum Component {
case text(String)
case tappable(String, () -> Void)
}
let components: [Component]