This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Here's an example of how to run a command to periodically keep homebrew up to date on your Mac: | |
| 1. Create a bash scrpit as below. | |
| ``` | |
| #!/bin/bash | |
| brew update && brew upgrade && brew cleanup | |
| ``` | |
| 2. Add a Permission |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alias xcode='xcode-select -p | cut -d '/' -f3 | xargs -I{} open -a {} $1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array where Element == NSLayoutConstraint { | |
| func activate() { | |
| self.forEach { (constraint) in | |
| constraint.isActive = true | |
| } | |
| } | |
| func deactivate() { | |
| self.forEach { (constraint) in | |
| constraint.isActive = false | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol UUIDRepresentable: RawRepresentable { | |
| associatedtype RawValue = String | |
| } | |
| extension UUIDRepresentable where Self.RawValue == String { | |
| func uuid() -> String { | |
| return self.rawValue | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol UUIDRepresentable: RawRepresentable { | |
| } | |
| extension UUIDRepresentable where Self.RawValue == String { | |
| func uuid() -> String { | |
| return self.rawValue | |
| } | |
| } | |
| enum hogeInt : Int, UUIDRepresentable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension NSLayoutAttribute { | |
| func toString() -> String { | |
| switch self { | |
| case .Left: return "Left" | |
| case .Right: return "Right" | |
| case .Top: return "Top" | |
| case .Bottom: return "Bottom" | |
| case .Leading: return "Leading" | |
| case .Trailing: return "Trailing" | |
| case .Width: return "Width" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| display notification "Foo Bar" & (time string of(current date)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var action1: () -> Void = {} | |
| var action2: ()->() = {} | |
| let result1 = action1() | |
| let result2 = action2() | |
| print(type(of: result1)) | |
| print(type(of: result2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import CoreMotion | |
| struct SimpleMovingAvgQueue{ | |
| typealias EulerAngles = (roll: Double, pitch: Double, yaw: Double) | |
| var eulerAngles = Array<EulerAngles>() | |
| let capacity: Int | |
| init(capacity cap: Int) { | |
| self.capacity = cap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array where Element: FloatingPoint { | |
| func simpleMovingAverage(scope:Int) -> [Element]? { | |
| guard self.count >= scope else { return nil } | |
| var result = [Element]() | |
| for endIndex in scope...self.count { | |
| let lower = endIndex-scope | |
| let upper = endIndex | |
| let range = Range(uncheckedBounds: (lower: lower, upper: upper)) | |
| let sum = self[range].reduce(0) { (v1, v2) -> Element in return v1+v2 } | |
| let avg = sum/Element(scope) |
NewerOlder