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 / MainActivity.kt
Created August 7, 2024 13:35
SampleModalBottomSheet
package com.example.testmbs
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@y2k
y2k / effector.kt
Created June 3, 2023 21:06
Kotlin Effector
package com.example.frpeffsample.effector
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@y2k
y2k / domain.kt
Last active June 3, 2023 21:05
Effector - Kotlin - TodoList
val addClicked = Event.create<Unit>()
val textChanged = Event.create<String>()
val itemDeleted = Event.create<Int>()
private val itemAdded = Event.create<String>()
val storeText = Store.create("")
.on(textChanged) { _, newText -> newText }
.reset(itemAdded)
type WebPart = interface end
let reduceWebPart rules =
let emptyNodeParse _ n = failwithf "No resolver for: %O" n
let rec makeReducer (next: (WebPart -> _) -> WebPart -> _) (wp: WebPart) =
next (makeReducer next) wp
makeReducer (rules |> List.fold (fun a b -> b a) emptyNodeParse)
// ===============
@y2k
y2k / domain.clj
Created November 26, 2021 13:53
Events driven arch
(ns domain)
(listen-event
:item-created
(fn [e]
{:fetch {:url "https://backend.com/save"
:body {:text (:text e)}}}))
package kotlin.time
inline class Instant(val value: Duration) : Comparable<Instant> {
companion object {
val ZERO = Instant(Duration.ZERO)
fun fromUnixTimeSeconds(time: Long): Instant =
Instant(time.seconds)
class OpenClass { }
class FirstOpenClass : OpenClass { }
class SecondOpenClass : OpenClass { }
class Foo <TGen> where TGen : OpenClass, new() {
public TGen open = new TGen();
}
SecondOpenClass foo = new Foo<SecondOpenClass>().open;
open class OpenClass
class FirstOpenClass : OpenClass()
class SecondOpenClass : OpenClass()
class Foo<TGen : OpenClass>(
val open: TGen = FirstOpenClass() as TGen
) {
companion object {
fun build() = Foo(FirstOpenClass()) //it’s OK
}
static class ResultPair {
String response;
List<User> altered;
}
public Response subscriptionConfirmed(Message message, int addDays, String messageText, String userFilter) {
LocalDateTime now = LocalDateTime.now();
List<User> users = findUsers(message.getFrom(), userFilter);
ResultPair result = pureLogic(message, addDays, now, users);
@y2k
y2k / hackathon.fs
Created December 20, 2019 17:19
hackathon
open System
open FSharp.Data
type OnboardingType = XmlProvider<".data/onboarding.xml">
module Domain =
open SlackAPI
let toBlocks (cmd : OnboardingType.Command) : IBlock array =
cmd.Items
|> Seq.map ^ fun x ->