Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Mochamad Iqbal Dwi Cahyo mochadwi

💭
I may be slow to respond.
View GitHub Profile
@gmk57
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
antoniolg / MainActivity.kt
Last active Dec 22, 2020
Shows how to use permissions with registerForActivityResult(). Code for https://devexperto.com/permisos-android-11
View MainActivity.kt
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
@rharter
rharter / Scoped.kt
Last active Mar 16, 2021
A kotlin property delegate to scope any object to an android lifecycle. Blog post at https://ryanharter.com/blog/easy-android-scopes/
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
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
cerebrl / rewriting-git-history.md
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.
View rewriting-git-history.md

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 report.md

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
AbdElraoufSabri / Readme.md
Last active Nov 27, 2019
AndroidX manual Migration script
View Readme.md

Procedure

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

Long link

  1. curl -s -L https://gist.githubusercontent.com/AbdElraoufSabri/907163eecbb87e7ca033d01004623c05/raw/executor.sh | bash

short link

  1. curl -s -L https://git.io/JevZ4 | bash

short link #2

@gsavvid
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 https://gist.github.com/Robyer/a6578e60127418b380ca133a1291f017.
* 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
loganj / script.sh
Last active Mar 3, 2021 — forked from dlew/script.sh
Simple AndroidX Migration Script
View script.sh
#!/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: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#