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
var dict: [String: Any?] = ["a": nil, "b": 0, "c": 1]
// 1. Map and comapctMap
// This works. Although the dictionary value is still optional even though it could never be nil here 👍
let mappedDict = dict.map { return $0.value != nil ? $0 : nil }.compactMap { $0 }
print(mappedDict)
// 2. Filter
// Filtering achieves the same
let filteredDict = dict.filter { $0.value != nil }
@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
@jimmyhoran
jimmyhoran / .gitattributes
Created March 29, 2020 06:51 — forked from asmallteapot/.gitattributes
Diff Xcode localizable strings files in Git.
*.strings utf16 diff=localizablestrings
import UIKit
extension UITableView {
/// Layout `UITableView.headerView` with autolayout.
func layoutTableHeaderView() {
guard let headerView = tableHeaderView else { return }
layout(headerView)
self.tableHeaderView = headerView
}
extension Optional where Wrapped: Collection {
var isNilOrEmpty: Bool {
return self?.isEmpty ?? true
}
}
// MARK: - Tests
func testNilOrEmpty() {
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
@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
@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 / 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 / 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)