Skip to content

Instantly share code, notes, and snippets.

View nachtien's full-sized avatar
👋

Nick Achtien nachtien

👋
View GitHub Profile
import androidx.compose.animation.core.EaseInOut
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
@c5inco
c5inco / CollapsingTabBar.kt
Last active May 28, 2024 11:14
Jetpack Compose implementation of inspirational design https://twitter.com/philipcdavis/status/1486871621600104450
package des.c5inco.material3
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@smaharj1
smaharj1 / chasebank.js
Last active July 19, 2024 22:26
Chase bank auto apply offers
/**
APPLY CHASE BANK CC OFFERS
This script helps you apply all the Chase bank credit cards automatically.
- Login to Chase and go to https://secure03b.chase.com/web/auth/dashboard#/dashboard/offers/index.
- Open 'Inspect Element'
- Go to Scripts tab and copy this script.
- Run this script.
*/
@c5inco
c5inco / MaterialMotionTransitions.kt
Last active December 7, 2023 08:12
Reusable transitions that map to Material 2 motion system - https://material.io/develop/android/theming/motion
// Requires Compose 1.1.0-alpha02+
// Best used with navigation animation transitions in Accompanist 0.17.0+
import androidx.compose.animation.*
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
@lhwdev
lhwdev / TextFieldDecoration.kt
Created July 9, 2021 07:55
A TextField that does nothing with ime and allows you to put arbitrary contents
import androidx.compose.animation.animateColor
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.ZeroCornerSize
import androidx.compose.material.*
@saantiaguilera
saantiaguilera / Result.kt
Created January 14, 2021 17:07
Result sealed class for kotlin error handling, allowing us to write safe code either in a functional or imperative format, without the use of exceptions. Since kotlin from 1.3 onwards changed their Result into an inline class, we can no longer use it for return values (which eliminates the bad smell of exceptions as errors, like most modern lang…
package com.saantiaguilera
import com.saantiaguilera.Result.Failure
import com.saantiaguilera.Result.Success
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
/**
* A discriminated union that encapsulates successful outcome with a value of type [S]
@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
@jamiesanson
jamiesanson / ViewLifecycleLazy.kt
Last active May 29, 2024 10:43
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
@ologe
ologe / PreferenceExtensions.kt
Last active November 13, 2024 21:10
Android shared preference observer using kotlin coroutines (1.3.0)
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> = channelFlow {
send(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
trySend(getItem(key, default))
}
}
registerOnSharedPreferenceChangeListener(listener)
@davidair
davidair / AsyncActivity.kt
Created November 9, 2018 23:12
A base class activity that leverages Kotlin coroutines and allows streamlining activity invocation
/**
* Copyright 2017 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software