Skip to content

Instantly share code, notes, and snippets.

View y2k's full-sized avatar
🏠
Working from home

y2k

🏠
Working from home
View GitHub Profile
@y2k
y2k / scheme.txt
Created July 10, 2019 13:22
Fullstack Native Mobile Architecture
+----------------------------------------+ +----------------------------------------+
| | | |
| Mobile App Process | | Server Process |
| | | |
| +-----------+ +----------------+ | | +-------------+ +--------------------+ |
| | Android +---+ | | | | | | | | |
| | UIToolkin | | | V8 JS Engine | | Swagger | | Backend API | | Static JS bundle | |
| +-----------+ | | | | JSON | | | | | |
| | Android | | | Compiled to JS +----------------> | | from F#/Kotlin/... | |
| | Compose +-----+-+ * F# | | ProtoBuf | | +-------+-+---+ | |
@y2k
y2k / compose-ru.md
Last active September 19, 2019 15:37
Перевод "Compose From First Principles"

Оригинал: Compose From First Principles

Основные принципы Compose

В начале текущего месяца (7 мая 2019) тысячи разработчиков со всего мира посетили Google I/O 2019. Для меня (Leland Richardson) данное предприятие было особенно интересным, поскольку именно на нем компания Google представила Jetpack Compose, проект, для работы над которым я был нанят в феврале 2018 года.

Compose является самым амбициозным проектом, по переосмыслению Android UI Toolkit, с момента выпуска Android c оригинальным UI Toolkit.

Если вы еще не посмотрели [сессию "Declarative UI Patterns"][1], то там был комплексный обзор мотиваций и целей этого проекта, о которых речь в посте не идет. В этой статье обсуждаются подробности реализации, тк что если вы хотите узнать мотивации данного проекта, посмотрите сессию!

fun runRobolectric(action: suspend () -> Unit) {
val result = AtomicReference<Result<Unit>>()
@Suppress("EXPERIMENTAL_API_USAGE")
MainScope().launch {
try {
action()
} catch (e: Throwable) {
result.set(Result.failure(e))
} finally {
@y2k
y2k / lite-moxy.kt
Created February 15, 2019 13:13
lite moxy
interface LitePresenter<T : Any> {
fun attachView(view: LiteView<T>)
fun detachView()
}
open class BaseLitePresenter<T : Any> : LitePresenter<T> {
private val buffer = ArrayList<T>()
private var view: LiteView<T>? = null
private var firstAttached = false
@y2k
y2k / sequence-guessing-game.kt
Last active February 9, 2019 13:59
Пример асинхронной программы, без kotlinx.coroutines
package example1
import java.util.concurrent.ThreadLocalRandom
typealias F = SequenceScope<Eff<*>>
sealed class Eff<T> {
class WriteLine(val text: String, val f: (Unit) -> Unit = {}) : Eff<Unit>()
class ReadLine(val f: (String) -> Unit = {}) : Eff<String>()
class Random(val min: Int, val max: Int, val f: (Int) -> Unit = {}) : Eff<Int>()
@y2k
y2k / app.kt
Created December 29, 2018 12:54
NoSQL example
suspend fun main(args: Array<String>) {
val db = LiteDb(DesktopConnector, ":memory:")
db.insert(mkRandomUser())
db.insertAll(List(10) { mkRandomUser() })
val users = // List<User>
db.query(UserMeta) {
and {
it.age lt 20
@y2k
y2k / virtual-ui.kt
Last active December 17, 2018 11:22
package y2k.virtual.ui
import android.animation.LayoutTransition
import android.animation.ObjectAnimator
import android.animation.StateListAnimator
import android.app.MediaRouteButton
import android.app.SearchableInfo
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
// private suspend fun find(context: Context, destination: String): String? {
// val intent = Intent().setComponent(ComponentName(destination, IdentifierService::class.java.name))
// return context.executeInService(intent) { ISharedIdentifier.Stub.asInterface(it).get() }
// }
suspend fun <T : Any> Context.executeInService(intent: Intent, extract: (IBinder) -> T): T? =
suspendCancellableCoroutine { continuation ->
val connection = createConnection(this, continuation, extract)
continuation.invokeOnCancellation { unbindService(connection) }
@y2k
y2k / litemoxy.kt
Last active September 28, 2022 13:06
Lite Moxy
/*
* Репозиторий с примером
* https://github.com/y2k/LiteMoxy/tree/master/app/src/main/java/im/y2k/litemoxy
*/
import android.support.v4.app.Fragment
abstract class MvpPresenter<T : Any> {
val view: MvpView<T> = BufferView()
type User = { email: String; name: String; surname: String }
type Model =
{ user: User
editedUser: User
emailValid: Boolean
buttonEnabled: Boolean
buttonText: String }
type Source = Email | Name | Surname