Skip to content

Instantly share code, notes, and snippets.

View jimmyhoran's full-sized avatar
🛠️
Working on my own thing

Jimmy Horan jimmyhoran

🛠️
Working on my own thing
View GitHub Profile
@jimmyhoran
jimmyhoran / SafeAccessToKeyWindow.swift
Last active July 1, 2021 08:49
Safe access to the `keyWindow` for iOS 13+ support of multiple UIScene
let keyWindow = UIApplication.shared.connectedScenes
.filter { $0.activationState == .foregroundActive }
.map { $0 as? UIWindowScene }
.compactMap { $0 }
.first?.windows
.filter { $0.isKeyWindow }
.first
// Usage e.g.
_ = keyWindow?.safeAreaInsets.bottom ?? 0
@jimmyhoran
jimmyhoran / lint-devices-file.sh
Last active May 14, 2021 03:33
Script to complete a basic check of the fastlane devices.txt file format, where it must use tabs.
#!/usr/bin/env bash
#
# lint-devices-file
# Usage example: ./scripts/ios/lint-devices-file fastlane/devices.txt
FILE=$1
TAB_COUNT=$(grep "$(printf '\t')" $FILE | wc -l)
NEW_LINE_COUNT=$(grep "$(printf '\n')" $FILE | wc -l)
@jimmyhoran
jimmyhoran / bump-ios-app-version.sh
Created May 7, 2021 06:00
Scripts to bump iOS app versions components and build number
#!/usr/bin/env bash
#
# bump-ios-app-version
# Usage example: ./bump-ios-app-version minor apps/app-ios-parking/SupportingFiles/Info.plist
component=$1
info_plist_path=$2
version=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' ${info_plist_path})
@jimmyhoran
jimmyhoran / kill-all-emulators.sh
Created April 26, 2021 06:59
Kill all running emulators
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
@jimmyhoran
jimmyhoran / config
Created April 26, 2021 00:07
How to resolve ssh `client_loop: send disconnect: Broken pipe` - set "~/.ssh/config"
Host *
ServerAliveInterval 600
TCPKeepAlive yes
IPQoS=throughput
extension UIViewController {
/// Traverse up the responder chain until we find a `UINavigationController`.
func findNavigationController() -> UINavigationController? {
if let nextResponder = self.next as? UINavigationController {
return nextResponder
} else if let nextResponder = self.next as? UIViewController {
return nextResponder.findNavigationController()
} else {
return nil
extension Optional where Wrapped: Collection {
var isNilOrEmpty: Bool {
return self?.isEmpty ?? true
}
}
// MARK: - Tests
func testNilOrEmpty() {
import UIKit
extension UITableView {
/// Layout `UITableView.headerView` with autolayout.
func layoutTableHeaderView() {
guard let headerView = tableHeaderView else { return }
layout(headerView)
self.tableHeaderView = headerView
}
@jimmyhoran
jimmyhoran / .gitattributes
Created March 29, 2020 06:51 — forked from asmallteapot/.gitattributes
Diff Xcode localizable strings files in Git.
*.strings utf16 diff=localizablestrings
@jimmyhoran
jimmyhoran / web-servers.md
Created December 11, 2019 10:43 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000