Skip to content

Instantly share code, notes, and snippets.

View iAmrSalman's full-sized avatar

Amr Salman iAmrSalman

View GitHub Profile
@iAmrSalman
iAmrSalman / .git-commit-template.txt
Created February 22, 2018 19:03 — forked from adeekshith/.git-commit-template.txt
This commit message template that helps you write great commit messages and enforce it across your team.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@iAmrSalman
iAmrSalman / NetworkManager.swift
Last active March 2, 2018 14:43
[NetwokManager] #swift4 #Alamofire #ObjectMapper
import UIKit
import Alamofire
import ObjectMapper
typealias NetworkSuccessClosure = (BaseModel?) -> Void
typealias NetworkFailureClosure = (Error?) -> Void
class NetworkManager: NSObject {
class func startRequest<T: BaseModel>(withRequestConfiguration request: RequestConfiguraton, andMappingObject objectClass: T?, successClouser success: NetworkSuccessClosure?, andFailure failure: NetworkFailureClosure?) {
@iAmrSalman
iAmrSalman / XLPagerTabStrip.swift
Created March 10, 2018 21:23
[XLPagerTabStrip] #swift #XLPagerTabStrip
import UIKit
import XLPagerTabStrip
class ProfileTabsVC: ButtonBarPagerTabStripViewController {
//MARK: - Life Cycle
override func viewDidLoad() {
setupPager()
super.viewDidLoad()
@iAmrSalman
iAmrSalman / PhoneNumberManager.swift
Created March 21, 2018 14:15
[PhoneNumberManager] validate and format phoneNumber using PhoneNumberKit
import Foundation
import PhoneNumberKit
enum Format {
case e164
case national
case international
}
class PhoneNumberManager {
@iAmrSalman
iAmrSalman / ContactsManager.swift
Last active May 26, 2021 21:25
[ContactsManager] fetch all contacts from Phone Contacts using Contacts framework #swift4 #contacts
import Foundation
import ContactsUI
enum ContactsFilter {
case none
case mail
case message
}
struct PhoneContact {
@iAmrSalman
iAmrSalman / timeAgoSinceDate.swift
Last active March 30, 2018 05:55
[timeAgoSinceDate] #date #swift
class func timeAgoSince(_ date: Date, from currentDate: Date = Date(), numericDates: Bool = false) -> String {
let calendar = Calendar.current
let now = currentDate
let earliest = (now as NSDate).earlierDate(date)
let latest = (earliest == now) ? date : now
let components:DateComponents = (calendar as NSCalendar).components([NSCalendar.Unit.minute , NSCalendar.Unit.hour , NSCalendar.Unit.day , NSCalendar.Unit.weekOfYear , NSCalendar.Unit.month , NSCalendar.Unit.year , NSCalendar.Unit.second], from: earliest, to: latest, options: NSCalendar.Options())
if (components.year! >= 2) {
return "\(components.year!) years ago"
} else if (components.year! >= 1){
@iAmrSalman
iAmrSalman / Sociable.swift
Last active April 8, 2018 09:40
[Sociable] protocol to handle social deeplinking #swift #protocol
import UIKit
import MessageUI
protocol Sociable: MFMailComposeViewControllerDelegate, UINavigationControllerDelegate {
func openInstagramAccount(withID id: String)
func openTwitterAccount(withID id: String)
func openFacebookAccount(withID id: String)
func openSnapchatAccount(withID id: String)
func sendEmail(to email: String, withDefaultMessage message: String)
func call(_ mobileNumber: String)
UIFont.familyNames.sorted().forEach{ familyName in
print("*** \(familyName) ***")
UIFont.fontNames(forFamilyName: familyName).forEach { fontName in
print("\(fontName)")
}
print("---------------------")
}
/*
*** Academy Engraved LET ***
@iAmrSalman
iAmrSalman / getThumbnail.swift
Last active May 17, 2018 07:30
[Generate Video Thumbnail] function to generate video thumbnail using AVFoundation #avfoundation
//Don't forget to import AVFoundation
func getVideoThumbnail(from path: URL?) -> UIImage? {
guard let path = path else { return nil }
do {
let asset = AVURLAsset(url: path , options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(0, 1), actualTime: nil)
let thumbnail = UIImage(cgImage: cgImage)
@iAmrSalman
iAmrSalman / getVideoDuration.swift
Last active October 27, 2024 13:04
[Get video duration] function to get video duration #video
//Don't forget to import AVFoundation
func getVideoDuration(from path: URL) -> String {
let asset = AVURLAsset(url: path)
let duration: CMTime = asset.duration
let totalSeconds = CMTimeGetSeconds(duration)
let hours = Int(totalSeconds / 3600)
let minutes = Int((totalSeconds.truncatingRemainder(dividingBy: 3600)) / 60)
let seconds = Int(totalSeconds.truncatingRemainder(dividingBy: 60))