Skip to content

Instantly share code, notes, and snippets.

View hoc081098's full-sized avatar
✝️
Glory to God

Petrus Nguyễn Thái Học hoc081098

✝️
Glory to God
View GitHub Profile
@hoc081098
hoc081098 / proguard-rules.pro
Created October 17, 2023 08:24
proguard-rules.pro
#### Nav
-keepnames class androidx.navigation.fragment.NavHostFragment
-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable
#### OkHttp, Retrofit and Moshi
-dontwarn okhttp3.**
@hoc081098
hoc081098 / MainActivity.kt
Last active September 12, 2023 09:45
Jetpack Navigation 2.4.+ multi back stacks back behavior and solution
/*
* Copyright 2019, The Android Open Source Project
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@hoc081098
hoc081098 / rememberIsScrollingUpState.kt
Created August 19, 2023 18:36
rememberIsScrollingUpState.kt
@Composable
private fun LazyListState.rememberIsScrollingUpState(): State<Boolean> {
var previousIndex by remember(this) { mutableIntStateOf(firstVisibleItemIndex) }
var previousScrollOffset by remember(this) { mutableIntStateOf(firstVisibleItemScrollOffset) }
return remember(this) {
derivedStateOf {
if (previousIndex != firstVisibleItemIndex) {
previousIndex > firstVisibleItemIndex
@hoc081098
hoc081098 / NavHost.kt
Created August 18, 2023 09:46
NavHost.kt
@Composable
fun <T: Any> rememberMutableStateListOf(vararg elements: T): SnapshotStateList<T> {
return rememberSaveable(
saver = listSaver(
save = { stateList ->
if (stateList.isNotEmpty()) {
val first = stateList.first()
if (!canBeSaved(first)) {
throw IllegalStateException("${first::class} cannot be saved. By default only types which can be stored in the Bundle class can be saved.")
import 'package:video_player/video_player.dart';
class VideoQuestion extends StatefulWidget {
final String videoUrl;
VideoQuestion({Key? key, required this.videoUrl})
: super(key: key);
@override
State<VideoQuestion> createState() => _VideoQuestionState();
import android.app.AppOpsManager
import android.app.AppOpsManager.OnOpChangedListener
import android.content.Context
import android.os.Build
import android.os.Process
import androidx.core.content.getSystemService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
fun main() {
var delta = -1
val m = 3
val offsets: List<Int> = (0..10).scan(0) { acc, _ ->
(acc + delta).also {
if (it == -m || it == m) {
delta = -delta
}
}

attribute vec4 a_Position; attribute vec2 a_TexCoordinate; varying vec2 v_TexCoordinate; void main() { v_TexCoordinate = a_TexCoordinate; gl_Position = a_Position; }
ChatGPT This is a simple vertex shader written in GLSL (OpenGL Shading Language).

class MyEffectPreviewView : GLView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
private var index = 0
private var bitmaps: List<Bitmap> = emptyList()
override fun onGLDraw(canvas: ICanvasGL) {
val bitmaps = this.bitmaps
val index = this.index
@hoc081098
hoc081098 / flow_redux.kt
Last active April 24, 2023 18:36
flow_redux.kt
// ----------------------------------------------------------------------------- Domain
interface HomeRepository {
suspend fun fetchData(): String
suspend fun syncData()
fun observeData(): Flow<String>
}
// -----------------------------------------------------------------------------Demo: Home screen UI
sealed interface HomeAction {
object FetchData : HomeAction