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 / copy-git-commits.txt
Created March 31, 2019 04:21
Copy git commits across repositories
/path/to/1 $ git format-patch sha1^..sha1
/path/to/1 $ cd /path/to/2
/path/to/2 $ git am -3 /path/to/1/0001-…-….patch
import UIKit
import PlaygroundSupport
extension UIView {
/// Anchor self to `view` center x and y axis.
///
/// - parameters:
/// - centerX: Center align to the view along the x axis.
/// - centerY: Center align to the view along the y axis.
@jimmyhoran
jimmyhoran / Docs.md
Last active August 30, 2019 03:05
For a cleaner and simpler copyright header for all Xcode projects, when placed in ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist

The full list of locations that Xcode searches, in order of priority:

Project - single user

<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/

Project - shared by all users

<ProjectName>.xcodeproj/xcshareddata/

@jimmyhoran
jimmyhoran / BenchmarkCodeExecution.swift
Created June 4, 2019 11:14
Helper functions to benchmark Swift code execution time
import UIKit
func printTimeElapsedExecuting(title: String, operation: () -> Void) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("Time elapsed for \(title): \(timeElapsed)s.")
}
func timeElapsedInSecondsExecuting(operation: () -> Void) -> Double {
@jimmyhoran
jimmyhoran / NormaliseData.swift
Last active June 4, 2019 11:28
Swift data normalisation
import Foundation
/// Normalise a value to a 0...1 range.
func normalise(value: Double, lower: Double, upper: Double) -> Double {
return max(0.0, min(1.0, (value - lower) / (upper - lower)))
}
normalise(value: 0, lower: 0, upper: 2) // -> 0
normalise(value: 1, lower: 0, upper: 2) // -> 0.5
normalise(value: 22, lower: 0, upper: 50) // -> 0.44
@jimmyhoran
jimmyhoran / accidental-hard-reset.sh
Created June 29, 2019 02:44
For when I accidently --hard reset 🤯
git fsck --lost-found
@jimmyhoran
jimmyhoran / enable-build-times-for-xcode.sh
Created July 6, 2019 01:52
Show build duration times in Xcode IDE
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
@jimmyhoran
jimmyhoran / Dictionary+CaseInsensitive.swift
Created July 15, 2019 09:03
Dictionary extension for case insensitive value lookups
import Foundation
extension Dictionary where Key == String {
func valueForInsensitive<T>(key: Key) -> T? {
let key = keys.first { $0.compare(key, options: .caseInsensitive) == .orderedSame } ?? key
return self[key] as? T
}
}
import Foundation
enum Debug {
static func print(_ item: @autoclosure () -> Any, separator: String = " ", terminator: String = "\n") {
#if DEBUG
Swift.print(item(), separator: separator, terminator: terminator)
#endif
}
}
@jimmyhoran
jimmyhoran / git-clean-untracked-things.md
Last active August 18, 2019 02:00
Git: Clean untracked things

Git Cleaning

See which files will be deleted.

git clean -n

To delete the untracked files for good.

git clean -f

Some other handy commands to remove untracked things

  • To remove directories, run git clean -fd