Skip to content

Instantly share code, notes, and snippets.

View amadeu01's full-sized avatar
:octocat:
Working from Stockholm

Amadeu Cavalcante Filho amadeu01

:octocat:
Working from Stockholm
View GitHub Profile
@amadeu01
amadeu01 / spotlessKotlin.txt
Created August 21, 2019 20:05
spotless kotlin lint
src/ConduitAPIServer.kt
@@ -1,3 +1,4 @@
+/*·Licensed·under·MIT·*/
package·dev.amadeu
import·io.ktor.application.*
@@ -10,7 +11,7 @@
/**
·*·Conduit·API
@amadeu01
amadeu01 / build.gradle
Created August 21, 2019 19:32
Gradle config for ktlint
ktlint {
version = "0.34.0"
debug = true
verbose = true
android = false
outputToConsole = true
reporters = [ReporterType.CHECKSTYLE]
ignoreFailures = true
enableExperimentalRules = true
filter {
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
@amadeu01
amadeu01 / Logger.swift
Created May 27, 2019 14:34
Timber like swift :P
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) {
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) {
//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)
@amadeu01
amadeu01 / Bundle.swift
Last active May 7, 2019 21:50
Bundle extension with useful swizzling
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(
@amadeu01
amadeu01 / PhoneFormatter.swift
Created March 19, 2019 17:15
PhoneFormatter for eureka.
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
@amadeu01
amadeu01 / String+email.swift
Created March 11, 2019 12:45
String nice extensions
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)
}
}
@amadeu01
amadeu01 / InjectedFragment.kt
Last active December 12, 2018 12:14
Injected Fragment for Kodein
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") {}