Skip to content

Instantly share code, notes, and snippets.

@rishabhkohli
rishabhkohli / !!ViewLifecycleAware.kt
Last active December 29, 2021 17:41 — forked from jamiesanson/ViewLifecycleLazy.kt
A Kotlin delegated property implementation which automatically clears itself at appropriate times in the View Lifecycle of a Fragment.
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleAware(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
private var value: T? = null
@raymyers
raymyers / PostalTranslations.java
Created January 18, 2013 20:47
Mapping State/Province names to abbreviations and vice versa for United States and Canada in Java using Google Guava immutable collections. Includes handling for non-standard abbreviations associated with Quebec and Newfoundland.
import java.util.Map;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;