Skip to content

Instantly share code, notes, and snippets.

@tylermilner
tylermilner / setup-macos-runner.sh
Last active June 18, 2023 23:57
A script to aid in setting up a Mac for use as a GitHub Actions self-hosted runner.
#!/bin/bash
# The name of the runner user account
RUNNER_USERNAME="runner"
RUNNER_FULLNAME="$RUNNER_USERNAME"
# Check for sudo access
echo "Checking for root access..."
# Check if running as root
if [ $EUID != 0 ]; then
@tylermilner
tylermilner / averageBuildTime.sh
Created May 1, 2020 15:34
A simple Bash script to generate an average build time for your iOS project. Replace with your project's workspace and scheme before use.
#!/bin/bash
# Workspace and scheme parameters for the project
workspace="ProjectWorkspace.xcworkspace" # TODO: Replace with your project's workspace
scheme="ProjectScheme" # TODO: Replace with your project's scheme
# The number of times to build the project
numRuns=3
# Abort the process if any of the commands in this script fail
@tylermilner
tylermilner / oclint.sh
Last active March 12, 2019 19:00 — forked from ryuichis/gist:755e6297aec13c900cdf
Script integrating OCLint into Xcode 10. Put it in "Run script" build phase of aggregate target (see http://docs.oclint.org/en/stable/guide/xcode.html). Replace "<project_name>" and tweak "exclude" flags as necessary.
source ~/.bash_profile
unset LLVM_TARGET_TRIPLE_SUFFIX
xcodebuild -scheme <project_name> -workspace <project_name>.xcworkspace clean
xcodebuild -scheme <project_name> -workspace <project_name>.xcworkspace COMPILER_INDEX_STORE_ENABLE=NO | xcpretty -r json-compilation-database --output compile_commands.json
maxPriority=15000
oclint-json-compilation-database -exclude Pods -exclude build -- -report-type xcode -max-priority-1=$maxPriority -max-priority-2=$maxPriority -max-priority-3=$maxPriority
@tylermilner
tylermilner / Slow_Compiling_Swift_Code.swift
Created November 27, 2017 22:55
Code samples of common sources of slowdowns for the Swift 2/3 compiler.
//
// The code snippets below showcase common "problem code" that can take a long time to compile.
// These examples were primarily observed in Swift 2/3 and may no longer be relevant in Swift 4 or higher.
//
/// 1. Array concatenation
// Observed by Robert Gummesson - https://medium.com/@RobertGummesson/regarding-swift-build-time-optimizations-fc92cdd91e31#c75c
// Joining two arrays together with the '+' operator can be expensive to compile.
let someArray = ["a", "b"] + ["c", "d"]
@tylermilner
tylermilner / Cupcakes_MapAndFlatMap.swift
Last active July 10, 2019 20:59
A Swift playground showcasing some use cases for map and flatMap using Cupcakes.
import UIKit
/// Introduction
// This playground showcases many potential use cases of `map` and `flatMap` in Swift (beyond transforming collections).
// See this article on Medium for more information: https://medium.com/rocket-fuel/step-up-your-functional-game-map-and-flatmap-tricks-cdc1578fe7bc
// To run this playground in Xcode, copy/paste the contents of this file into a new playground (playgrounds are technically directories so GitHub Gist doesn't work well with them).
// There are several comment blocks that represent the "old way" of doing things (without `map`/`flatMap`). Feel free to uncomment these to verify functionality.
@tylermilner
tylermilner / copy_appropriate_google-service-info-plist.sh
Last active November 16, 2024 18:28
A shell script to selectively copy your GoogleService-Info.plist into your app bundle based on the current build configuration.
# Name of the resource we're selectively copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
# Get references to dev and prod versions of the GoogleService-Info.plist
# NOTE: These should only live on the file system and should NOT be part of the target (since we'll be adding them to the target manually)
GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Dev/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Prod/${GOOGLESERVICE_INFO_PLIST}
# Make sure the dev version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_DEV}"
#
#### DEPRECATED ####
# Use the standard .swiftlint.yml for all files in your project, including tests.
# https://gist.github.com/tylermilner/f33e33e3b4f23d8c6b2fdd4f87af98a1
#
# Set max line length before warning (default is 120)
line_length: 240
disabled_rules:
@tylermilner
tylermilner / .swiftlint.yml
Last active May 5, 2021 20:10
Default SwiftLint repo-wide configuration file. Put this at the root directory of your repository and tweak for your needs.
# Turn off default SwiftLint rules
disabled_rules:
- trailing_whitespace # Disables SwiftLint complaining about whitespace characters on empty lines
- todo # Disables auto-warning of TODO statements
# Turn on extra SwiftLint rules
opt_in_rules:
- array_init
- attributes
- closure_end_indentation
@tylermilner
tylermilner / Xcode Breakpoints.swift
Last active August 24, 2023 17:08
These are Xcode breakpoints I've found to be very useful to have turned on to help debug iOS applications and spot problems early. After creating each one, right-click on it and click "Move Breakpoint To" -> "User" so that the breakpoint will automatically be active for any Xcode project you open.
All Objective-C Exceptions
// Catches exceptions thrown by Objective-C code.
// Default Xcode breakpoint created by clicking "+" to add breakpoint -> "Exception Breakpoint".
// Change "Exception: All" to "Exception: Objective-C".
-[UIApplication main]
// Helps when printing objects via the debugger by making it aware of the classes in UIKit.
// Symbolic breakpoint created by clicking "+" to add breakpoint -> "Symbolic Breakpoint".
// Enter "-[UIApplication main]" for the Symbol.
// Choose Action -> "Debugger Command".
@tylermilner
tylermilner / RadioStationAPI Code&Tell Example
Last active March 27, 2017 15:55
RadioStationAPI - Code & Tell Snippets
1.) Create 'api.raml' file:
#%RAML 1.0
title: Radio Station
version: v1
baseUri: http://api.samplehost.com
2.) Layout basic API structure: