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 / customRule.kt
Created September 14, 2019 16:28
Custom Rule for ktlint
class CustomRuleSetProvider : RuleSetProvider {
override fun get() = RuleSet("rules",
NoInternalImportRule(),
NoVarRule()
)
}
class NoInternalImportRule : Rule("no-internal-import") {
override fun visit(
node: ASTNode, autoCorrect: Boolean,
@amadeu01
amadeu01 / build.gradle
Created August 21, 2019 20:51
Set ktlint with html reporter
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt --reporter=html,artifact=me.cassiano:ktlint-html-reporter:0.2.3,output=${buildDir}/ktlint.html"
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
@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)
// Created by Amadeu Cavalcante Filho on 11/05/19.
// Copyright © 2019 Amadeu Cavalcante Filho. All rights reserved.
//
import Foundation
public struct Task<T, E: Error> {
public typealias Closure = (Controller<T, E>) -> Void
private let closure: Closure
@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(