Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Mochamad Iqbal Dwi Cahyo mochadwi

I may be slow to respond.
View GitHub Profile
gmk57 / Sending events to UI.kt
Last active Mar 28, 2021
Sending events to UI with Channel/Flow + custom collector (see my first comment for reasons behind it)
View Sending events to UI.kt
* Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop.
* This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case
* the coroutine is just suspended on stop.
inline fun <reified T> Flow<T>.collectWhileStarted(
lifecycleOwner: LifecycleOwner,
noinline action: suspend (T) -> Unit
) {
object : DefaultLifecycleObserver {
antoniolg / MainActivity.kt
Last active Dec 22, 2020
Shows how to use permissions with registerForActivityResult(). Code for
View MainActivity.kt
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
rharter / Scoped.kt
Last active Mar 16, 2021
A kotlin property delegate to scope any object to an android lifecycle. Blog post at
View Scoped.kt
import androidx.lifecycle.get
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
* Returns a property delegate to access the wrapped value, which will be retained for the
* duration of the lifecycle of this [ViewModelStoreOwner].
krossovochkin / Error.kt
Created Feb 23, 2020
From RxJava to Kotlin Flow: Error Handling
View Error.kt
package by.krossovochkin.testflow
import io.reactivex.Observable
import io.reactivex.exceptions.CompositeException
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.Test
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.CountDownLatch
cerebrl /
Last active Mar 21, 2020
Understand how rewriting history with `git amend` and `git rebase` can be crucial in keeping your Git logs clean and simple, while avoiding some dangerous consequences.

Rewriting Git History

Say you have a code base that you just created and you have two commits locally:

commit a
commit b

This is your “version history”. You then push these commits to your remote. Now you have two repos with the same history:

View gist:57c6a48b068548e29d63d5aa12379e38
* What went wrong:
Execution failed for task ':app:checkDebugAndroidTestDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.ArtifactStatus found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.ArtifactUtils found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.DefaultArtifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1
View sample issue

Issue General Information

This is a sample issue to be used as a template for every bugs or even suggestion for improvement. Issue raised in each repository better be following this sample issue structure. The first section is general info of the issue while this paragraph also works as an general info example. Every problem occurred in development cycle MUST be written as repository issue to ease problem follow-ups.

Step to Reproduce

  1. In this section you need to describe the steps to reproduce the issue
  2. The steps written needs to be as detailed and complete as possible
  3. Since this will help devs to trace and find the solution
AbdElraoufSabri /
Last active Nov 27, 2019
AndroidX manual Migration script


  1. Open terminal from android studio or navigate to the projet's root directory

Long link

  1. curl -s -L | bash

short link

  1. curl -s -L | bash

short link #2

gsavvid / publishMavenBintray.gradle
Last active Sep 28, 2020 — forked from Robyer/maven-publish-helper-usage.gradle
Gradle script for publishing Android Kotlin libraries to a Bintray repository using maven-publish plugin. With dependencies (also handling transitive: false and custom exclude rules), including sources and javadoc.
View publishMavenBintray.gradle
* Publish Android Kotlin Library Helper
* This Gradle script is based on
* The difference is that:
* 1. It uses Dokka for generating Kotlin Javadoc.
* 2. It uses Jfrog's plugin for publishing to Bintray. If you don't want to publish to Bintray, simply remove all the Bintray-related code.
* NOTE: You need to add Dokka and Bintray to your classpath for the two plugins to work.
* Update the buildscript in your project's build.gradle with the following:
loganj /
Last active Mar 3, 2021 — forked from dlew/
Simple AndroidX Migration Script
#!/usr/bin/env bash
# Original by Dan Lew
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
# You can download a CSV of package names here:
# It'll run faster on a clean build because then there are fewer files to scan over.