Skip to content

Instantly share code, notes, and snippets.

View eleev's full-sized avatar

Astemir Eleev eleev

View GitHub Profile
eleev / URLForPHAsset.swift
Last active February 17, 2024 23:56
Getting URL for PHAsset (Swift 3.0)
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) {
if mPhasset.mediaType == .image {
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
return true
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
eleev / UIImage+Inset.swift
Created August 5, 2022 09:52
UIImage Inset - blank space around a UIImage
import UIKit
public extension UIImage {
func image(uniformInset inset: CGFloat) -> UIImage? {
top: inset,
left: inset,
bottom: inset,
right: inset
eleev / UIImage+SolidColor.swift
Created March 24, 2017 11:18
Extension for creating UIImage from a UIColor. Swift 3
extension UIImage {
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
let rect = CGRect(origin: .zero, size: size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
let image = UIGraphicsGetImageFromCurrentImageContext()
guard let cgImage = image?.cgImage else { return nil }
eleev /
Created May 9, 2019 07:51
Git branch renaming [local & remote]
git branch -m old_branch new_branch # First, rename branch locally
git push origin :old_branch # Then, delete the outdated branch
git push --set-upstream origin new_branch # And finally, push the new branch. Also, the new remote needs to be tracked, that is why we set set local branch to do so.
eleev / iOS UIFont Names (Raw).swift
Created July 30, 2018 07:19
Use the following reference to properly construct UIFont instances with valid font names
UIFont: family Thonburi
UIFont: font Thonburi-Bold
UIFont: font Thonburi
UIFont: font Thonburi-Light
UIFont: family Khmer Sangam MN
UIFont: font KhmerSangamMN
UIFont: family Snell Roundhand
UIFont: font SnellRoundhand-Black
UIFont: font SnellRoundhand-Bold
UIFont: font SnellRoundhand
eleev / KeyCodesMacOS.swift
Created July 29, 2018 15:54
The code snippet contains key codes for `macOS` keyboard
import Carbon
struct KeyCode {
static let a = UInt16(kVK_ANSI_A)
static let b = UInt16(kVK_ANSI_B)
static let c = UInt16(kVK_ANSI_C)
static let d = UInt16(kVK_ANSI_D)
static let e = UInt16(kVK_ANSI_E)
static let f = UInt16(kVK_ANSI_F)
static let g = UInt16(kVK_ANSI_G)
eleev / DispatchQueue+DispatchOnce.swift
Last active March 30, 2018 14:13
DispatchOnce + Swift 3 (and above).swift
public extension DispatchQueue {
// MARK: - Properties
private static var _onceTracker = [String]()
// MARK: - Methods
/// Executes a block of code, associated with a unique token, only once. The code is thread safe and will onle execute the code once even in the presence of multithreaded calls.
eleev / UIImage+Resize.swift
Created March 26, 2017 11:44
Class-level extension for UIImage that allow to resize input image based on expected image width or/and height. Swift 3
extension UIImage {
class func resize(_ image: UIImage, newWidth: CGFloat) -> UIImage? {
let scale = newWidth / image.size.width
let newHeight = image.size.height * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
eleev / UIImage+TiffOrientationFix.swift
Created March 24, 2017 13:08
This calss-level UIImage extension aims to help identifying raw value for UIImageOrientation. This may be useful when warking with CGImage or CIImage classes. Swift 3
extension UIImage {
class func imageOrientationToTiffOrientation(_ value: UIImageOrientation) -> Int32 {
switch (value) {
case .up:
return 1
case .down:
return 3
case .left:
return 8
case .right: