Skip to content

Instantly share code, notes, and snippets.

@LouisCAD
LouisCAD / Flow <-> LiveData.kt
Created October 23, 2019 15:35
Convert a Flow to a LiveData and use LiveData as a Flow (from kotlinx.coroutines).
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.liveData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.*
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
@Atavic
Atavic / properties_system_android.md
Created January 29, 2018 22:10
Android System Properties
@dhwaneetbhatt
dhwaneetbhatt / ArrayMatrixIterator.java
Last active September 1, 2022 16:24
List and array iterators for iterating over a matrix
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.google.common.base.Preconditions;
/**
* Provides data from a matrix represented using a 2D array
*
* @author Dhwaneet Bhatt
* @since Aug 17, 2016
@atoennis
atoennis / SomeFragment.java
Last active April 23, 2020 06:30
Solution to having nested scrolling within Android. In this scenario a multiline EditText resides within a root level ScrollView. In order to have scroll momentum, the EditText itself doesn't scroll but it is wrapped within a ScrollView.
// When the EditText is touched, disable touches on it's ScrollView's parents.
// Once the user lifts up their finger, enable touches on on the ScrollView's parents once again.
@OnTouch(R.id.edit_text)
boolean handleNoteFieldTouch(View v, MotionEvent event) {
v.getParent().getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
@psayre23
psayre23 / gist:c30a821239f4818b0709
Last active June 8, 2024 19:07
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array