Skip to content

Instantly share code, notes, and snippets.

View charlesmuchene's full-sized avatar
😎
Kotlin, checking out Rust-lang

Charles Muchene charlesmuchene

😎
Kotlin, checking out Rust-lang
View GitHub Profile
@charlesmuchene
charlesmuchene / DataRequest+TwoDecodableResponseHandler.swift
Created February 12, 2020 19:06
Custom handler using custom serializer
extension DataRequest {
/// Decodes the response to a type `T` or` APIError`.
///
/// NB: The serializer used `TwoDeodableResponseSerializer` doesn't throw though Alamofire
/// response serializer expects to receive a `DataResponse`. All errors/failures are converted to an `APIError`.
///
/// - Parameters:
/// - t: Type to decode to
/// - queue: `DispatchQueue` to dispatch `completionHandler`
//
// AuthenticationDataHandler.swift
// Bonfire
//
// Created by Charles Muchene on 2/10/20.
// Copyright © 2020 SenseiDevs. All rights reserved.
//
import Alamofire
import Foundation
@charlesmuchene
charlesmuchene / SingleMethodUseCase.kt
Created February 21, 2020 03:57
Single Method UseCase
interface UseCase {
fun invoke()
}
class UseCaseImpl: UseCase {
override fun invoke() {
println("Invalidate cache")
}
}
@charlesmuchene
charlesmuchene / SingleMethodUseCase.swift
Created February 21, 2020 04:00
Single Method UseCase
protocol UseCase {
func invoke()
}
class UseCaseImpl: UseCase {
func invoke() {
debugPrint("Invalidate cache")
}
}
@charlesmuchene
charlesmuchene / SingleMethodInvocableUseCase.kt
Created February 21, 2020 04:47
Single method invocable usecase
interface UseCase {
operator fun invoke()
}
class UseCaseImpl: UseCase {
override fun invoke() {
println("Invalidate cache")
}
}
@charlesmuchene
charlesmuchene / SingleMethodInvocableUseCase.swift
Created February 21, 2020 06:07
Single method invocable usecase
@dynamicCallable
protocol UseCase {
func invoke()
}
extension UseCase {
func dynamicallyCall(withArguments: [Void]) {
invoke()
}
}
@charlesmuchene
charlesmuchene / toy.kt
Created February 28, 2020 12:03
Toy class
data class Toy(val id: String, val name: String, val color: Int)
@charlesmuchene
charlesmuchene / toyviewholder.kt
Created February 28, 2020 12:05
Toy View holder
class ToyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(toy: Toy) {
// TODO Bind toy to view
}
}
@charlesmuchene
charlesmuchene / toyviewadapter.kt
Created February 28, 2020 12:07
Toy View Adapter
class ToyViewAdapter : RecyclerView.Adapter<ToyViewHolder>() {
private val toys = mutableListOf<Toy>()
fun addToys(vararg toys: Toy) {
val start = toys.size - 1
this.toys.addAll(toys)
notifyItemRangeInserted(start, toys.size)
}
@charlesmuchene
charlesmuchene / unique.kt
Created February 28, 2020 13:18
Unique Interface
interface Unique<T> {
val id: T
}