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 / thread.kt
Created April 4, 2020 11:20
Thread with an indefinite loop
fun seriousWork() = thread(name = "Worker") {
while (!Thread.currentThread().isInterrupted) {
// Perform Genetic Sequencing
}
}
@charlesmuchene
charlesmuchene / fragment+recyclerview.kt
Created March 20, 2020 09:36
Fragment hosting a recycler view
class HomeFragment : Fragment() {
private val adapter = Adapter()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? =
inflater.inflate(R.layout.fragment_home, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@charlesmuchene
charlesmuchene / network.kt
Last active March 13, 2020 17:51
Network call using coroutines
interface ApiService {
@GET("status")
suspend fun getStatus(): Response<Status>
}
class LearningCoroutinesViewModel @Inject constructor(private val apiService: ApiService) :
ViewModel() {
fun getStatus() {
@charlesmuchene
charlesmuchene / uniquetoy.kt
Created February 28, 2020 13:26
Toy adopting Unique interface
data class Toy(override val id: String, val name: String, val color: Int): UniqueList.Unique<String>
@charlesmuchene
charlesmuchene / unique.kt
Created February 28, 2020 13:18
Unique Interface
interface Unique<T> {
val id: T
}
@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 / 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 / toy.kt
Created February 28, 2020 12:03
Toy class
data class Toy(val id: String, val name: String, val color: Int)
@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 / 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")
}
}