Skip to content

Instantly share code, notes, and snippets.

Avatar

Gabriel Peal gpeal

View GitHub Profile
@gpeal
gpeal / Fails.kt
Last active Aug 17, 2020
Kotlin 1.4 Type Inference
View Fails.kt
class TypeInference {
private val fails: Int by badTypeInference()
private val succeeds by badTypeInference<TypeInference, Int>()
}
object Helper {
inline fun <T, reified P> T.badTypeInference() = object : PropertyDelegateProvider<T, P>() {
override fun provideDelegate(thisRef: Any, property: KProperty<*>) = lazy { P::class.java.newInstance() }
}
@gpeal
gpeal / MyViewModel.kt
Last active Mar 13, 2020
Fetching data
View MyViewModel.kt
data class MyState(
/** Use this to render the UI */
val fetchedGroups: List<Whatever> = emptyList()
/** Use this to show loading state/errors */
val groupsRequest: Async<Unit> = Uninitialized
) : MvRxState
class MyViewModel(initialState: MyState) : MvRxViewModel<MyState>(initialState) {
init {
View FragmentExtensions.kt
/**
* Show fragment's view in a dialog, similar to [androidx.fragment.app.DialogFragment],
* but without need to extend it. Should be called from [Fragment.onViewCreated].
*
* Add this Fragment without giving it a container view then call this from onViewCreated
*/
fun Fragment.showAsDialog(
@StyleRes theme: Int = R.style.FullScreenDialog,
widthDp: Int? = null,
heightDp: Int? = null,
@gpeal
gpeal / stack.txt
Created Jun 14, 2019
MvRx reflection ConcurrentModiifcationException
View stack.txt
java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
at java.util.HashMap$KeyIterator.next(HashMap.java:814)
at java.util.jar.JarVerifier.readCertificates(JarVerifier.java:266)
at java.util.jar.JarFile.getInputStream(JarFile.java:380)
at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
at java.net.URL.openStream(URL.java:470)
at java.util.ServiceLoader$ServiceIterator.readClass(ServiceLoader.java:224)
at java.util.ServiceLoader$ServiceIterator.hasNext(ServiceLoader.java:202)
at kotlin.collections.CollectionsKt___CollectionsKt.firstOrNull(_Collections.kt:220)
@gpeal
gpeal / convert.js
Last active Jun 5, 2019
This will convet a Lottie json file that doesn't have "ty" properties at the beginning of the object to one that does.
View convert.js
const fs = require('fs');
convert = (json) => {
if (typeof json != "object") {
return json
}
for (var key in json) {
if (json.hasOwnProperty(key)) {
json[key] = convert(json[key])
}
View CoroutineExecute.kt
fun <T : Any?> execute(
fn: suspend () -> T,
onError: (suspend (Exception) -> Unit)? = null,
dispatcher: CoroutineDispatcher = Dispatchers.Default,
reducer: S.(Async<T>) -> S
) {
uiScope.launch(dispatcher) {
setState { reducer(Loading()) }
try {
val result = fn()
View CounterFragment.kt
package com.airbnb.mvrx.counter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.BaseMvRxFragment
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MvRxState
View gist:3b6cb4aaac2468aca407f81fe9193db3
Repo: https://github.com/airbnb/lottie-android.git
Start time: 2018-11-15T17:46:26Z
$ docker "run" "-v" "/var/run/docker.sock:/var/run/docker.sock" "-v" "/bitrise:/bitrise" "-v" "/tmp/bitrise-agent270117773:/.bitrise-config" "--privileged" "--network=host" "--name=bitrise-main-container" "bitriseio/android:pinned" "bitrise" "run" "--config" "/.bitrise-config/bitrise.yml" "--inventory" "/.bitrise-config/bitrise.secrets.yml" "--json-params-base64" "eyJ3b3JrZmxvdyI6InZhbGlkYXRpb25fd29ya2Zsb3dfbm9fc3NoIn0="
██████╗ ██╗████████╗██████╗ ██╗███████╗███████╗
██╔══██╗██║╚══██╔══╝██╔══██╗██║██╔════╝██╔════╝
██████╔╝██║ ██║ ██████╔╝██║███████╗█████╗
██╔══██╗██║ ██║ ██╔══██╗██║╚════██║██╔══╝
██████╔╝██║ ██║ ██║ ██║██║███████║███████╗
View ViewBinders.kt
package com.yourapp
import android.support.annotation.IdRes
import android.support.v4.app.Fragment
import android.view.View
import android.view.ViewGroup
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
private object UNINITIALIZED
View HelloWorldFragment.kt
data class HelloWorldState(val title: String = "Hello World") : MvRxState
class HelloWorldViewModel(initialState: HelloWorldState) : MvRxViewModel<HelloWorldState>(initialState) {
fun getMoreExcited() = setState { copy(title = "$title!") }
}
class HelloWorldFragment : BaseFragment() {
private val viewModel by fragmentViewModel(HelloWorldViewModel::class)
override fun EpoxyController.buildModels() = withState(viewModel) { state ->
You can’t perform that action at this time.