Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
View hasNil (operate on optional array)
/**
* Asserter
*/
extension Array {
/**
* Asserts if array has nil values
* ## Examples:
* let someArr: [Int?] = [1,2,nil]
* someArr.hasNil() // true
* [1,2,2].hasNil() // false
View CheapFlights (Mobility challenge)
# CheapFlights (Mobility challenge)
- Use api's from top 3 flight aggregators (use google to find them) 💻
- Searchbar with: input destination and departure, input time 🗺
- Get cheapest tickets (direct flight only) ✈️
- Present with basic info in table view 📝
- Present detail view if item is pressed 👇
- Pull table to refresh (or refresh button if web-app) ⬇️
## Challenges:
@eonist
eonist / UITableView+Extension.swift
Created May 2, 2020
UITableView+Extension.swift
View UITableView+Extension.swift
import UIKit
extension UITableViewDataSource where Self: UITableView {
/**
* Returns a cells in table
* - Note: Unlike native cell(for index) or visibleCells calls, this call wont break/complain even when called before the cells are available
*/
var availableCells: [UITableViewCell] {
self.subviews.compactMap { $0 as? UITableViewCell }
}
View gist:9bf74542b9ffc6e98d6e9321fb9ae262
extension UIViewController {
/**
* Traverses the entire VC hirearchy downwards and collects VC'w that are of speccific PARAM: type
* - Fixme: ⚠️️ this can be written more elegantly with flatMap
* ## Example:
* let vc: CustomVC? = UIApplication.shared.delegate?.window?.rootViewController?.descendants().first
*/
func descendants<T>(type: T.Type? = nil) -> [T] {
var childrenOfType: [T] = []
self.children.forEach {
@eonist
eonist / Payroll.swift
Last active Dec 23, 2019
Xmas challenge
View Payroll.swift
struct Employee {
let name: String
let sallary: Double
let role: Role
enum Role: String {
case it, hr, managment
}
}
func payMonthly(employees: [Employee]) {
employees.forEach { payMonthly(employee: $0) }
@eonist
eonist / QRVersionTableTest.swift
Created Dec 12, 2019
a small method to convert qrversion table to a more machine readable format
View QRVersionTableTest.swift
import Foundation
final class QRVersionTableTest {}
extension QRVersionTableTest {
/**
* convertQRVersionTable
* - Note: a small method to convert qrversion table to a more machine readable format
*/
static func convertQRVersionTable() {
Swift.print("convertQRVersionTable")
View VerticalAlignedLabel.swift
import UIKit
/**
* Example:
* let label: VerticalAlignedLabel = UILabel()
* label.contentMode = .bottom
* Ref: https://stackoverflow.com/questions/18247934/how-to-align-uilabel-text-from-bottom
* TODO: ⚠️️ Maybe we could just do sizeThatFits fitToSize etc or just us TextField?
* Todo: this is cool but its not precise enough. this is more precise: https://stackoverflow.com/a/51761518
* let size = text.size(withAttributes:[.font: UIFont.systemFont(ofSize:18.0)])
*/
@eonist
eonist / GestureHUD_ AppDelegate.swift
Created Sep 7, 2017
GestureHUD companion xcode project (AppDelegate.swift)
View GestureHUD_ AppDelegate.swift
import Cocoa
@testable import Utils
@testable import Element
@NSApplicationMain
class AppDelegate:NSObject, NSApplicationDelegate {
weak var window:NSWindow!
var win:NSWindow?/*<--The window must be a class variable, local variables doesn't work*/
var menu:Menu?
View Forced Notifications
NSUserNotificationCenter.default.delegate = self//add this in the applicationDidFinishLaunching call
extension AppDelegate:NSUserNotificationCenterDelegate{
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}
}
@eonist
eonist / LinearPressure.swift
Created Jul 26, 2017
linearPressure for forcetouch
View LinearPressure.swift
/**
* NOTE: calculates the entire range of the stage pressures so from stage 0 to 1 the pressure goes from 0 to 0.5 and from stage 1 to 2 the linear pressure goes from 0.5 to 1 this makes it easier to scale things in a linear fashion from 0 to 1 in the entire stage range
*/
var linearPressure:CGFloat{
if event.stage == 0 {
return 0
}else if event.stage == 1{
return pressure / 2
}else /*if stage == 2*/ {
return 0.5 + (pressure / 2)
You can’t perform that action at this time.