Skip to content

Instantly share code, notes, and snippets.


Astemir Eleev jVirus

View GitHub Profile
jVirus / URLForPHAsset.swift
Last active Jun 22, 2020
Getting URL for PHAsset (Swift 3.0)
View URLForPHAsset.swift
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
jVirus / UIImage+SolidColor.swift
Created Mar 24, 2017
Extension for creating UIImage from a UIColor. Swift 3
View UIImage+SolidColor.swift
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 }
jVirus /
Created May 9, 2019
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.
jVirus / iOS UIFont Names (Raw).swift
Created Jul 30, 2018
Use the following reference to properly construct UIFont instances with valid font names
View iOS UIFont Names (Raw).swift
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
jVirus / KeyCodesMacOS.swift
Created Jul 29, 2018
The code snippet contains key codes for `macOS` keyboard
View KeyCodesMacOS.swift
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)
jVirus / DispatchQueue+DispatchOnce.swift
Last active Mar 30, 2018
DispatchOnce + Swift 3 (and above).swift
View DispatchQueue+DispatchOnce.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.
jVirus / UIImage+Resize.swift
Created Mar 26, 2017
Class-level extension for UIImage that allow to resize input image based on expected image width or/and height. Swift 3
View UIImage+Resize.swift
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()
jVirus / UIImage+TiffOrientationFix.swift
Created Mar 24, 2017
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
View UIImage+TiffOrientationFix.swift
extension UIImage {
class func imageOrientationToTiffOrientation(_ value: UIImageOrientation) -> Int32 {
switch (value) {
case .up:
return 1
case .down:
return 3
case .left:
return 8
case .right:
jVirus / UIImage+LandscapeCameraCaptureOrientationFix.swift
Created Mar 24, 2017
This extension for UIImage fixes image orientation for cases when the iamge was captured using AVFoundation in landscape interface orientation. Swift 3
View UIImage+LandscapeCameraCaptureOrientationFix.swift
func landscapeCameraCaptureOrientationFix(for interfaceOrinetation: UIInterfaceOrientation) -> UIImage? {
var imageOrientation: UIImageOrientation!
var shouldOrient: Bool = false
if interfaceOrinetation == .landscapeRight {
imageOrientation = UIImageOrientation.left
shouldOrient = !shouldOrient
} else if interfaceOrinetation == .landscapeLeft {
imageOrientation = UIImageOrientation.right
You can’t perform that action at this time.