Skip to content

Instantly share code, notes, and snippets.

View nachtien's full-sized avatar
👋

Nick Achtien nachtien

👋
View GitHub Profile
@jamiesanson
jamiesanson / ViewLifecycleLazy.kt
Last active March 26, 2024 13:17
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 {
@joyrexus
joyrexus / README.md
Last active February 24, 2024 15:16
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
@Darep
Darep / no-comments.js
Created May 30, 2016 07:01
Remove all comments from GitHub Pull Request
// Sometimes it's necessary to do a bit of clean-up
Array.prototype.forEach.call(document.querySelectorAll('.js-comment-delete button'), function(el, i) {
el.removeAttribute('data-confirm');
el.click();
});
@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
@smaharj1
smaharj1 / chasebank.js
Last active November 19, 2023 07:35
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.
*/
@ologe
ologe / PreferenceExtensions.kt
Last active July 13, 2023 10:25
Android shared preference observer using kotlin coroutines (1.3.0)
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> {
val flow = MutableStateFlow(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
flow.value = getItem(key, default)!!
}
}
registerOnSharedPreferenceChangeListener(listener)
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 August 17, 2022 00:05
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
@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]
@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.*