Skip to content

Instantly share code, notes, and snippets.

View cjbrooks12's full-sized avatar

Casey Brooks cjbrooks12

View GitHub Profile
@cjbrooks12
cjbrooks12 / ImmutableRandom.kt
Created August 16, 2022 18:26
Kotlin Immutable Random
import kotlin.random.Random
/**
* Denotes an instance of [Random] that does not mutate its own internal state. Unlike standard [Random],
* [ImmutableRandom] will always return the same value for subsequent calls to [nextBits], [nextInt], etc. One must
* call [nextRandom] to get a new instance of [ImmutableRandom] with a state that would typically have been updated
* internally.
*
* For the same seed, any sequence of `next*(), nextRandom()` should yield the same result as a normal [Random] calling
@cjbrooks12
cjbrooks12 / injector.kt
Created February 7, 2023 17:49
Ballast Repository Pattern
object Injector {
private val singletonCoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
private val repository = Repository(
coroutineScope = singletonCoroutineScope,
config = BallastViewModelConfiguration.Builder()
.withViewModel(
inputHandler = RepositoryInputHandler(),
initialState = RepositoryContract.State(),
name = "Repository",
)
@cjbrooks12
cjbrooks12 / ballastClicker.kt
Created March 1, 2023 15:41
Ballast Clicker
package com.copperleaf.ballast.clicker
import com.copperleaf.ballast.InputHandler
import com.copperleaf.ballast.InputHandlerScope
import kotlinx.coroutines.delay
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
@cjbrooks12
cjbrooks12 / diagram.md
Last active March 11, 2023 18:54
A sample master-detail view with Ballast and Compose

Data flow diagram

graph TD
    AppVM
    ListVM
    EditorVM
    
    AppVM -->|AppContract.State| ListVM
 ListVM -->|AppContract.Inputs| AppVM
enum class AppScreen(
routeFormat: String,
override val annotations: Set<RouteAnnotation> = emptySet(),
) : Route {
Home("/app/home"),
PostList("/app/posts?sort={?}"),
PostDetails("/app/posts/{postId}"),
;
override val matcher: RouteMatcher = RouteMatcher.create(routeFormat)