Skip to content

Instantly share code, notes, and snippets.

View galex's full-sized avatar

Alexander Gherschon galex

View GitHub Profile
@galex
galex / settings.gradle.kts
Created June 9, 2025 15:09
A few magic lines to configure modules to user their own name as the build file name
// Configure modules to use their own name as the build file name
// app/build.gradle.kts -> app/app.gradle.kts
// features/home/build.gradle.kts -> features/home/home.gradle.kts
rootProject.children.forEach { project ->
fun configureProject(project: ProjectDescriptor) {
project.buildFileName = "${project.name}.gradle.kts"
project.children.forEach { child ->
configureProject(child)
}
}
@galex
galex / EventDrivenViewModel.kt
Last active June 11, 2025 03:45
A little bit of inheritance and generics to have all events processed at the same place
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hobblies.libraries.architecture.extensions.forContext
import com.hobblies.libraries.architecture.extensions.eventDrivenState
import kotlinx.coroutines.channels.ProducerScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
abstract class EventDrivenViewModel<State, Event> : ViewModel() {
package com.example.myapplication
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.modifier.modifierLocalConsumer
package il.co.galex.alexpizzapp.utils
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistry
import androidx.activity.result.contract.ActivityResultContract
import androidx.compose.*
import androidx.ui.core.ContextAmbient
@galex
galex / 1_common.kt
Created April 13, 2019 05:43 — forked from yshrsmz/1_common.kt
Multiplatform ViewModel
expect abstract class ViewModel() {
open fun onCleared()
}
async(UI) {
// before using https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter
val call: Call<ApiResponse<List<VideoExtra>>> = service.getVideoExtras(userId)
val response: Response<ApiResponse<List<VideoExtra>>> = bg { call.execute() }.await()
// When using it, our code looks much better
val deferred: Deferred<Response<ApiResponse<List<VideoExtra>>>> = service.getVideoExtras(userId)
val response: Response<ApiResponse<List<VideoExtra>>> = deferred.await()
// using the response's data to set the value of LiveData(), etc...
}
@galex
galex / Preference.kt
Created February 6, 2018 05:30
Shared Preferences as Property Delegates (from the Kotlin for Android Developers book)
package com.talkingkotlin.util
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* Shared Preferences as Property Delegates (from the Kotlin for Android Developers book)
@galex
galex / Test.kt
Last active June 23, 2017 15:18
Test to outsmart smart casting
package il.co.kotlintlv.intro
var switch : Boolean = true
class Address(val street: String)
class Person {
val age: Int
val address: Address?
get() {
Verifying that +ghalex is my blockchain ID. https://onename.com/ghalex
###################################
## CartoDB 2.0 Install [Working] ##
## Tested on Ubuntu 12.04 ##
###################################
# Change password
passwd
adduser [username]
adduser [username] sudo