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 UIKit | |
| extension UIView { | |
| var firstResponder: UIView? { | |
| guard !isFirstResponder else { | |
| return self | |
| } |
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 UIKit | |
| extension UIView { | |
| var firstResponder: UIView? { | |
| guard !isFirstResponder else { | |
| return self | |
| } |
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 UIKit | |
| typealias AlertActionHandler = (_ action: UIAlertAction) -> Void | |
| extension UIAlertAction { | |
| static var okay: UIAlertAction { | |
| return UIAlertAction(title: "OK", style: .default, handler: nil) | |
| } |
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 UIKit | |
| extension UIViewController { | |
| @objc func presentErrorAlertWith(message: String, | |
| preferredStyle: UIAlertController.Style = .alert, | |
| handler: AlertActionHandler? = nil) { | |
| guard Thread.isMainThread else { |
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 UIKit | |
| struct Device { | |
| // MARK: - Singletons | |
| static var shared: UIDevice { | |
| struct Singleton { |
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 String { | |
| func encode(from: String.Encoding, to: String.Encoding) -> String? { | |
| guard let originalData = data(using: from) else { | |
| return nil | |
| } | |
| return String(data: originalData, encoding: to) | |
| } | |
| } |
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 UIKit | |
| var greeting = "Hello, playground" | |
| let key = "Test" | |
| let value = "test".data(using: .utf8)! | |
| let defaults = UserDefaults.standard | |
| func printUD() { | |
| print("UserDefaults after modification:\n") | |
| defaults.dictionaryRepresentation().forEach { print("\($0): \($1)\n") } |
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 java.util.Scanner; | |
| /* | |
| I see to often people using Scanner to get user input and just, plainly, screwing it. | |
| People don't seem to realise that they can use multiple Scanners to make life easier | |
| for themselves, for example, the primary Scanner can just be used to get the next line | |
| of text input by the user, then a secondary Scanner can be used to parse the input | |
| based on their needs. The following is a simple example to prompt the user for a int | |
| value, with a optional exit value and error message | |
| */ |
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
| protected Point2D pointOnEllipse(double angle, Point2D center, double width, double height) { | |
| width = width / 2d; | |
| height = height / 2d; | |
| angle = Math.toRadians(angle); | |
| double t = Math.atan(width * Math.tan(angle) / height); | |
| return new Point2D.Double(center.getX() + width * Math.cos(t), center.getY() + height * Math.sin(t)); | |
| } |