Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar

Alberto De Bortoli albertodebortoli

View GitHub Profile
@albertodebortoli
albertodebortoli / BrokenDismiss.swift
Created May 7, 2023 18:15
Showcasing the ViewController's dismiss method being broken in packages
import XCTest
import UIKit
@testable import DismissTest
class TopLevelUIUtilities {
private var rootWindow: UIWindow!
func setupTopLevelUI(withViewController viewController: UIViewController) {
@albertodebortoli
albertodebortoli / tech_radar.json
Last active August 26, 2022 09:29
tech_radar.json
[
{
"name": "Four key metrics",
"ring": "Adopt",
"quadrant": "Techniques",
"isNew": false,
"description": "asd"
}
]
@albertodebortoli
albertodebortoli / gist:0058860ba4ec12a089d81a4c34c771ac
Created September 15, 2020 19:55
Naughty Xcode: Free space commands
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Developer/Xcode/Archives
rm -rf ~/Library/Developer/Xcode/iOS\ DeviceSupport
rm -rf ~/Library/Caches/com.apple.dt.Xcode
xcrun simctl delete unavailable
https://stackoverflow.com/questions/41953300/how-to-delete-the-old-git-history
git checkout --orphan temp <f> # checkout to the status of the git repo at commit f; creating a branch named "temp"
git commit -m "new root commit" # create a new commit that is to be the new root commit
git rebase --onto temp <f> master # now rebase the part of history from <f> to master onthe temp branch
git branch -D temp # we don't need the temp branch anymore
@albertodebortoli
albertodebortoli / account_module_facade.swift
Created December 18, 2019 14:28
used by 'Modular iOS Architecture @ Just Eat' article on Medium
public typealias PasswordManagementService = ForgottenPasswordServiceProtocol & ResetPasswordServiceProtocol
public typealias AuthenticationService = LoginServiceProtocol & SignUpServiceProtocol & PasswordManagementService & RecaptchaServiceProtocol
public typealias UserAccountService = AccountInfoServiceProtocol & ChangePasswordServiceProtocol & ForgottenPasswordServiceProtocol & AccountCreditServiceProtocol
public class AccountModule {
public init(settings: Settings,
authenticationService: AuthenticationService,
userAccountService: UserAccountService,
socialLoginServices: [SocialLoginService],
userInfoProvider: UserInfoProvider)
@albertodebortoli
albertodebortoli / base64_decoding_function.swift
Created December 3, 2019 11:15
used by 'Lessons learned from handling JWT on mobile' article on Medium
func base64String(_ input: String) -> String {
var base64 = input
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
switch base64.count % 4 {
case 2:
base64 = base64.appending("==")
case 3:
@albertodebortoli
albertodebortoli / token_refresh_snippet_3.swift
Created December 3, 2019 11:11
used by 'Lessons learned from handling JWT on mobile' article on Medium
private func getValidUserAuthorizationInMutualExclusion(completion: @escaping (Result<AuthorizationValue, Error>) -> Void) {
semaphore.wait()
guard let authenticationInfo = authenticationInfoStore.userAuthenticationInfo else {
semaphore.signal()
let error = // forge an error for 'missing authorization'
completion(.failure(error))
return
}
@albertodebortoli
albertodebortoli / token_refresh_snippet_2.swift
Created December 3, 2019 11:08
used by 'Lessons learned from handling JWT on mobile' article on Medium
class AuthorizationValueProvider {
private let authenticationInfoStore: AuthenticationInfoStorage
private let tokenRefreshAPI: TokenRefreshing
private let queue = DispatchQueue(label: <#label#>, qos: .userInteractive)
private let semaphore = DispatchSemaphore(value: 1)
init(tokenRefreshAPI: TokenRefreshing,
authenticationInfoStore: AuthenticationInfoStorage) {
@albertodebortoli
albertodebortoli / token_refresh_snippet_1.swift
Created December 3, 2019 11:07
used by 'Lessons learned from handling JWT on mobile' article on Medium
typealias Token = String
typealias AuthorizationValue = String
struct UserAuthenticationInfo {
let bearerToken: Token // the JWT
let refreshToken: Token
let expiryDate: Date // computed on creation from 'exp' claim
var isValid: Bool {
return expiryDate.compare(Date()) == .orderedDescending
}

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream