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
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
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.*
data class State(val isLoading: Boolean = false, val items: List<Int> = emptyList())
sealed interface Reducer {
operator fun invoke(current: State): State
}
object LoadingReducer : Reducer {
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.*
data class State(val isLoading: Boolean = false, val items: List<Int> = emptyList())
fun interface Reducer {
operator fun invoke(current: State): State
}
val loadingReducer = Reducer { it.copy(isLoading = true) }
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.*
data class State(val isLoading: Boolean = false, val items: List<Int> = emptyList())
typealias Reducer = (current: State) -> State
val loadingReducer: Reducer = { it.copy(isLoading = true) }
val loadedReducer: Reducer = { it.copy(isLoading = false, items = listOf(1, 2, 3)) }
subprojects {
apply<KoverPlugin>()
afterEvaluate {
tasks.withType<Test> {
testLogging {
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
@hoc081098
hoc081098 / rememberSaveableStateHolder.kt
Created March 18, 2023 19:48
rememberSaveableStateHolder
package com.hoc081098.kmpviewmodelsample.android
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable