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 SwiftUI | |
struct CustomVStack<Content: View>: View { | |
let content: () -> Content | |
init(@ViewBuilder content: @escaping () -> Content) { | |
self.content = content | |
} | |
var body: some View { | |
VStack(spacing: 0) { |
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 re | |
def decode(text): | |
""" | |
Decodes the text using run-length encoding | |
""" | |
return re.sub(r'(\D)(\d*)', lambda m: m.group(1) * int(m.group(2)) if m.group(2) != '' else m.group(1), text) |
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
from itertools import groupby | |
def encode(text): | |
""" | |
Returns the run-length encoded version of the text | |
(numbers after symbols, length = 1 is skipped) | |
""" | |
splitted = list(text) | |
grouped = [list(j) for i, j in groupby(splitted)] |
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
typealias SortDescriptor<Value> = (Value, Value) -> Bool | |
protocol Sortable: class { | |
var sortRules: [SortRule] { get } | |
var currentRule: SortRule { get } | |
func sortData() | |
} | |
extension Sortable { |
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
struct MultipartRequest { | |
private let boundary = UUID().uuidString | |
private var bodyString: String = "" | |
private var body = Data() | |
var request: URLRequest | |
init( | |
url: URL, |
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
public enum ThrowableOptionalError: Error { | |
case unableToUnwrap | |
} | |
postfix operator +! | |
extension Optional { | |
public func unwrap() throws -> Wrapped { | |
switch self { | |
case .some(let value): |
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 CGPoint { | |
func scaled(to size: CGSize) -> CGPoint { | |
return CGPoint(x: self.x * size.width, y: self.y * size.height) | |
} | |
} |
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 UIImage { | |
func imageByApplyingClippingBezierPath(_ path: UIBezierPath) -> UIImage { | |
// Mask image using path | |
guard let let maskedImage = imageByApplyingMaskingBezierPath(path) else { return nil } | |
// Crop image to frame of path | |
let croppedImage = UIImage(cgImage: maskedImage.cgImage!.cropping(to: path.bounds)!) | |
return croppedImage | |
} |
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 UIImage { | |
func crop(toPreviewLayer layer: AVCaptureVideoPreviewLayer, withRect rect: CGRect) -> UIImage { | |
let outputRect = layer.metadataOutputRectConverted(fromLayerRect: rect) | |
var cgImage = self.cgImage! | |
let width = CGFloat(cgImage.width) | |
let height = CGFloat(cgImage.height) | |
let cropRect = CGRect( | |
x: outputRect.origin.x * width, | |
y: outputRect.origin.y * height, | |
width: outputRect.size.width * width, |
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 UIImage { | |
var flattened: UIImage? { | |
let ciImage = CIImage(image: self)! | |
guard let openGLContext = EAGLContext(api: .openGLES2) else { return nil } | |
let ciContext = CIContext(eaglContext: openGLContext) | |
let detector = CIDetector(ofType: CIDetectorTypeRectangle, | |
context: ciContext, | |
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])! |
NewerOlder