Skip to content

Instantly share code, notes, and snippets.

View kiarashvosough1999's full-sized avatar
🍉

Kiarash Vosough kiarashvosough1999

🍉
View GitHub Profile
import UIKit
public struct CocoStringAttributeHolder {
internal let key: NSAttributedString.Key
internal let value: Any
internal let range: Range<String.Index>?
fileprivate init(key: NSAttributedString.Key, value: Any, range: Range<String.Index>?) {
self.key = key
@kiarashvosough1999
kiarashvosough1999 / ExpandableList.swift
Created May 11, 2022 04:56
Expandable List SwifUI
struct ContentView: View {
@State var isExpanded = false
@State var subviewHeight : CGFloat = 0
var body: some View {
VStack {
Text("Headline")
VStack {
Text("More Info")
from cv2 import resize, INTER_LINEAR
from multiprocessing import Pool
def compare(args):
img, img2 = args
img = (img - img.mean()) / img.std()
img2 = (img2 - img2.mean()) / img2.std()
return np.mean(np.abs(img - img2))
class EpsilonPredictor:
@kiarashvosough1999
kiarashvosough1999 / TextInLabelDetector.swift
Created June 30, 2022 18:47
Detect Tap Attributed Text In Label
import UIKit
extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool {
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: CGSize.zero)
let textStorage = NSTextStorage(attributedString: label.attributedText!)
// Configure layoutManager and textStorage
struct ContentView: View {
@State var isExpanded = false
@State var subviewHeight : CGFloat = 0
var body: some View {
VStack {
Text("Headline")
VStack {
Text("More Info")
import UIKit
final class SceneManager {
var activityIdentifier: ActivityIdentifier? {
options
.userActivities
.compactMap { ActivityIdentifier(rawValue: $0.activityType) }
.first
}
import UIKit
#if canImport(Combine)
import Combine
@available(iOS 13.0, *)
final class ActionPublished: UIAction {
convenience init(actionSubject: InFailablePassThroughSubject<Void>?) {
self.init { [weak actionSubject] _ in
actionSubject?.send(())
import Combine
import CoreData
import Foundation
class CDPublisher<Entity>: NSObject, NSFetchedResultsControllerDelegate, Publisher where Entity: NSManagedObject {
typealias Output = [Entity]
typealias Failure = Error
private let request: NSFetchRequest<Entity>
private let context: NSManagedObjectContext
import Foundation
infix operator ->>: DefaultPrecedence
public protocol Castable {
func forceCast<U>(to type: U.Type) -> U
func AS<U>(to type: U.Type) -> U?
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher where Self.Failure == Never {
func assign(to failablePublished: CurrentValuePublished<Self.Output,Self.Failure>) -> AnyCancellable {
self.assign(to: \.wrappedValue, on: failablePublished)
}
}
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)