Skip to content

Instantly share code, notes, and snippets.

View vakhidbetrakhmadov's full-sized avatar

Vakhid Betrakhmadov vakhidbetrakhmadov

View GitHub Profile
@vakhidbetrakhmadov
vakhidbetrakhmadov / MKMapView+util.swift
Last active August 5, 2019 11:39
Zooming in on MKMapView to the MIN possible zoom level keeping map 'centered' at a specified coordinate.
import Foundation
import MapKit
extension MKMapView {
/// Region with MIN possible zoom level, such that self.centerCoordinate == center
func region(center: CLLocationCoordinate2D) -> MKCoordinateRegion {
var oldRegion: MKCoordinateRegion?
var newRegion: MKCoordinateRegion?
@vakhidbetrakhmadov
vakhidbetrakhmadov / AVAsset+util.swift
Last active October 24, 2024 11:45
Cropping video track to a specified crop rectangle.
import Foundation
import AVFoundation
extension AVAsset {
func cropVideoTrack(at index: Int, cropRect: CGRect, outputURL: URL, completion: @escaping (Result<Void, Swift.Error>) -> Void) {
enum Orientation {
case up, down, right, left
@vakhidbetrakhmadov
vakhidbetrakhmadov / KeyboardObserving.swift
Last active August 19, 2019 10:09
Utility protocol helping to simplify handling different keyboard notifications.
import UIKit
@objc protocol KeyboardObserving: class {
@objc optional func handleKeyboardWillShow(notification: Notification, keyboardSize: CGSize)
@objc optional func handleKeyboardWillHide(notification: Notification, keyboardSize: CGSize)
@objc optional func handleKeyboardWillChangeFrame(notification: Notification, keyboardSize: CGSize)
@objc optional func handleKeyboardDidChangeFrame(notification: Notification, keyboardSize: CGSize)
@vakhidbetrakhmadov
vakhidbetrakhmadov / AuthManager.swift
Last active August 19, 2019 10:14
Utility class build on top of p2/OAuth2 to simplify user login/logout and access token refreshing.
import Foundation
import p2_OAuth2
protocol AuthManagerProtocol {
var userLoggedIn: Bool { get }
func login(username: String, password: String, completion: @escaping Completion<Void>)
extension Sequence {
func grouped<T: Hashable>(by keyPath: KeyPath<Element, T>) -> [T: [Element]] {
return .init(grouping: self, by: { $0[keyPath: keyPath] })
}
}
@vakhidbetrakhmadov
vakhidbetrakhmadov / MemoryAddress.swift
Created January 14, 2020 20:35 — forked from nyg/MemoryAddress.swift
Get the memory address of both class and structure instances in Swift.
// https://stackoverflow.com/a/45777692/5536516
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size