This file contains 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 UIKit | |
typealias Replacer = String -> String | |
extension String { | |
var first: String { | |
return String(characters.prefix(1)) | |
} | |
} |
This file contains 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
public extension String { | |
public func split(length: Int) -> [String] { | |
let array = self.characters.map { String($0) } | |
let limit = self.characters.count | |
return 0 | |
.stride(to: limit, by: length) | |
.map({ | |
array[$0..<$0.advancedBy(length, limit: limit)].joinWithSeparator("") | |
}) | |
} |
This file contains 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 UIKit | |
enum NotificationKey: String { | |
case Hoge | |
} | |
//--------------- pattern1: use protocol-extension | |
protocol NSNotificationObservable: RawRepresentable { | |
var rawValue: String { get } |
This file contains 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
#!/bin/bash | |
calc_percentage() { | |
echo "$1/$2*100" | bc -l | awk '{s=($0<0)?-1:1;print int($0*s*100+0.5)/100/s;}' | |
} | |
arr=($(cloc --exclude-dir=Pods,Carthage --include-lang=Swift,Objective\ C ./ | sed -e '1,5d' | sed 's/-//g' | sed 's/Objective C/ObjectiveC/g' | awk '{print $5}' | grep -v -e 'code' -e '^S*$')) | |
swift_files=${arr[0]} | |
objc_files=${arr[1]} | |
sum=${arr[2]} |
This file contains 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 UIView { | |
static func animateIfNeeded(animated: Bool, duration: NSTimeInterval, animations: () -> Void, completion: ((Bool) -> Void)?) { | |
if animated { | |
self.animateWithDuration(duration, animations: animations, completion: completion) | |
} else { | |
animations() | |
completion?(true) | |
} | |
} | |
} |
This file contains 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 ReusableTableViewCell { | |
static var cellIdentifier: String { | |
return String(self) | |
} | |
} |
This file contains 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
#!/usr/bin/env xcrun swift | |
let arguments = Array(Process.arguments.dropFirst()) | |
print(arguments.joinWithSeparator(",")) |
This file contains 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
DispatchQueue.main.asyncAfter(deadline: .now() + __var__) { | |
} |
This file contains 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 CustomStringConvertible where Self: RawRepresentable { | |
var description: String { | |
return String(describing: self.rawValue) | |
} | |
} | |
enum Hoge: Int, CustomStringConvertible { | |
case a | |
} |
This file contains 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
_ = (Date(timeIntervalSinceNow: -100)..<Date()) ~= Date(timeIntervalSinceNow: -50) | |
// true |