This file contains hidden or 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 CoreData | |
| import Foundation | |
| /// Safely copies the specified `NSPersistentStore` to a temporary file. | |
| /// Useful for backups. | |
| /// | |
| /// - Parameter index: The index of the persistent store in the coordinator's | |
| /// `persistentStores` array. Passing an index that doesn't exist will trap. | |
| /// | |
| /// - Returns: The URL of the backup file, wrapped in a TemporaryFile instance |
This file contains hidden or 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 Data { | |
| var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription | |
| guard let object = try? JSONSerialization.jsonObject(with: self, options: []), | |
| let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]), | |
| let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil } | |
| return prettyPrintedString | |
| } |
This file contains hidden or 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 Accelerate.vImage | |
| func getImageBuffer(from pixelBuffer: CVPixelBuffer) -> vImage_Buffer? { | |
| var buffer = vImage_Buffer() | |
| let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.first.rawValue) | |
| var cgFormat = vImage_CGImageFormat(bitsPerComponent: 8, | |
| bitsPerPixel: 32, | |
| colorSpace: nil, | |
| bitmapInfo: bitmapInfo, | |
| version: 0, |
This file contains hidden or 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
| #!/bin/bash | |
| directory=_site | |
| branch=gh-pages | |
| build_command() { | |
| jekyll build | |
| } | |
| echo -e "\033[0;32mDeleting old content...\033[0m" | |
| rm -rf $directory |
This file contains hidden or 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
| StackOverflow answer by fl034 user. | |
| Link: https://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content/48623673#48623673 | |
| Swift 4.2 solution without KVO, DispatchQueue, or setting constraints yourself. | |
| This solution is based on Gulz's answer. | |
| 1) Create a subclass of UITableView: | |
| import UIKit |
This file contains hidden or 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
| // Zipping.swift | |
| // known-good: Swift 4.2 | |
| // Alexis Gallagher | |
| import Foundation | |
| public extension URL { | |
| /// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file | |
| /// |
This file contains hidden or 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 NSImage { | |
| /// Create a CIImage using the best representation available | |
| /// | |
| /// - Returns: Converted image, or nil | |
| func asCIImage() -> CIImage? { | |
| if let cgImage = self.asCGImage() { | |
| return CIImage(cgImage: cgImage) | |
| } | |
| return nil | |
| } |
This file contains hidden or 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 | |
| import Combine | |
| struct OnScroll: ViewModifier { | |
| @Binding var offset: CGFloat | |
| //we can have a version with a closure instead of the binding, but that triggers an infinite loop if content depends on the same Store | |
| // var onOffset: (CGFloat) -> () | |
| func body(content: Content) -> some View { | |
| return VStack { |
This file contains hidden or 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 resize(size: CGSize) -> UIImage? { | |
| guard let cgImage = self.cgImage else { return nil} | |
| var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, | |
| bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), | |
| version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent) | |
| var sourceBuffer = vImage_Buffer() |
This file contains hidden or 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 hkdf_sha256(_ seed: Data, salt: Data, info: Data, outputSize: Int = 32) -> Data? { | |
| // It would be nice to make this generic over <H: HashFunction> if HashFunction had byteCount instead of each hash | |
| // individually implementing it. | |
| let iterations = UInt8(ceil(Double(outputSize) / Double(SHA256.byteCount))) | |
| guard iterations <= 255 else { | |
| return nil | |
| } | |
| let prk = HMAC<SHA256>.authenticationCode(for: seed, using: SymmetricKey(data: salt)) | |
| let key = SymmetricKey(data: prk) |