Skip to content

Instantly share code, notes, and snippets.

View amfathi's full-sized avatar
🎧

Ahmed Fathi amfathi

🎧
View GitHub Profile
extension String {
/// Returns whether the string is a pangram or not
public func isPangram() -> Bool {
if count < 26 { return false }
var alphabetOccurances = Array(repeating: false, count: 26)
var totalCount = 0
for char in lowercased() {
if let ascii = char.asciiValue {
let index = Int(ascii) - 97
import Foundation
extension Array where Element == Int {
/// Returns a decoded version of a delta encoded array
public func deltaDecoded() -> [Element] {
let filteredArray = filterArray(self)
var cummulativeSum = 0
var decodedValues = [Element]()
@amfathi
amfathi / Reverse.swift
Last active April 21, 2020 08:08
Basic reversing algorithms for arrays and strings.
import Foundation
// MARK: - Reverse Array
func reverse<T>(array: [T]) -> [T] {
var reversedArray = array
var index = 0
while index < array.count {
reversedArray[index] = array[array.count - index - 1]
index += 1
}
@amfathi
amfathi / LinkedList.swift
Last active April 21, 2020 08:52
Naive implementation for a linked list.
import UIKit
// MARK: - Node
class Node<T: Equatable> {
var value: T?
var next: Node<T>?
var previous: Node<T>?
init() {}
}
import Foundation
// MARK: - Interval
struct Interval {
var low: Int
var high: Int
func overlaps(_ otherInterval: Interval) -> Bool {
return contains(otherInterval.low) || contains(otherInterval.high)
}
import Foundation
let mod = 10000000 // 10e7
func fastPow(base: Int, power: Int, mod: Int = mod) -> Int {
// Base cases
if base == 0 {
return 0
} else if power == 0 {
return 1
@amfathi
amfathi / Formatters.swift
Created February 28, 2020 13:51
Example of how your app should create formatters (Date, number, etc..)
enum Formatters {
static var apiDate: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
return formatter
}()
static var uiDisplay: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
@amfathi
amfathi / Colors.swift
Created February 23, 2020 13:22
Colors Extensions Sample
import UIKit
extension UIColor {
// MARK: - Backgrounds
static var mainBackground = UIColor(named: "mainBackground")!
static var secondaryBackground = UIColor(named: "secondaryBackground")!
static var elevatedBackground = UIColor(named: "elevatedBackground")!
static var separator = UIColor(named: "seperator")!
static var navigationBarTint = UIColor(named: "navigationBarTint")!
@amfathi
amfathi / BaseNavigationCoordinator.swift
Last active February 21, 2025 17:06
Coordinator (NavigationCoordinator + TabBarCoordinator)
import UIKit
// MARK: - Base Coordinator
class NavigationCoordinator: NSObject, Coordinator {
weak var parentCoordinator: Coordinator?
var childCoordinators = [Coordinator]()
var navigationController: BaseNavigationController
weak var startViewController: UIViewController?
@amfathi
amfathi / BaseCollectionViewCell.swift
Last active July 15, 2022 10:35
**Base** Views and Controllers (SnapKit + RxSwift)
import UIKit
class BaseCollectionViewCell: UICollectionViewCell, Identifiable {
override init(frame: CGRect) {
super.init(frame: .zero)
setupViews()
setupConstraints()
}