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
src/ConduitAPIServer.kt | |
@@ -1,3 +1,4 @@ | |
+/*·Licensed·under·MIT·*/ | |
package·dev.amadeu | |
import·io.ktor.application.* | |
@@ -10,7 +11,7 @@ | |
/** | |
·*·Conduit·API |
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
ktlint { | |
version = "0.34.0" | |
debug = true | |
verbose = true | |
android = false | |
outputToConsole = true | |
reporters = [ReporterType.CHECKSTYLE] | |
ignoreFailures = true | |
enableExperimentalRules = true | |
filter { |
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 UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application( | |
_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | |
) -> Bool { |
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 | |
public final class StandardFileHandle: TextOutputStream { | |
fileprivate let handle: FileHandle | |
public static let error = StandardFileHandle(handle: .standardError) | |
public static let output = StandardFileHandle(handle: .standardOutput) | |
public static let null = StandardFileHandle(handle: .nullDevice) | |
public init(handle: FileHandle) { |
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 URLSession { | |
func load(_ request: URLRequest, | |
_ completionHandler: @escaping (Result<(Data, HTTPURLResponse), ErrorEnvelope>) -> Void) { | |
dataTask(request) { result in | |
DispatchQueue.main.async { completionHandler(transformDataTask(result)) } | |
} | |
} | |
func dataTask(_ request: URLRequest, | |
_ completionHandler: @escaping (Result<(Data, HTTPURLResponse), AnyError>) -> Void) { |
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
//swiftlint:disable identifier_name redundant_void_return | |
precedencegroup ForwardApplication { | |
associativity: left | |
} | |
infix operator |>: ForwardApplication | |
public func |> <A, B>(x: A, f: (A) -> B) -> B { | |
return f(x) | |
} | |
public func |> <A: AnyObject>(x: A, f: (A) -> Void) -> Void { | |
f(x) |
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
private func swizzle(_ bundle: Bundle.Type) { | |
[(#selector(bundle.localizedString(forKey:value:table:)), | |
#selector(bundle.rd_localizedString(forKey:value:table:)))] | |
.forEach { original, swizzled in | |
guard let originalMethod = class_getInstanceMethod(bundle, original), | |
let swizzledMethod = class_getInstanceMethod(bundle, swizzled) else { return } | |
let didAddMethod = class_addMethod( |
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 class PhoneFormatter: Formatter, FormatterProtocol { | |
override public func getObjectValue( | |
_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, | |
for string: String, | |
errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool { | |
guard obj != nil else { return false } | |
let str = string.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "") | |
obj?.pointee = str as AnyObject | |
return 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
private let firstpart = "[A-Z0-9a-z]([A-Z0-9a-z._%+-]{0,30}[A-Z0-9a-z])?" | |
private let serverpart = "([A-Z0-9a-z]([A-Z0-9a-z-]{0,30}[A-Z0-9a-z])?\\.){1,5}" | |
private let emailRegex = firstpart + "@" + serverpart + "[A-Za-z]{2,8}" | |
private let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex) | |
extension String { | |
var isEmail: Bool { | |
return emailPredicate.evaluate(with: 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
abstract class InjectedFragment<T> : Fragment(), KodeinAware { | |
private val activityKodein by closestKodein() | |
override val kodein: Kodein by retainedKodein { | |
extend(activityKodein) | |
import(fragmentModule(parseBundle(arguments))) | |
} | |
open fun fragmentModule(data: T?) = Kodein.Module("activityModule") {} |