Skip to content

Instantly share code, notes, and snippets.

View Sintrastes's full-sized avatar

Nathan BeDell Sintrastes

View GitHub Profile
@Sintrastes
Sintrastes / BuildComposeForm.kt
Last active March 22, 2024 02:09
Messing around with compose runtime APIs
// Here's an example of how to return a state flow from the composable.
fun <A, B> buildComposeViewForm(
context: Context,
content: @Composable ViewScope.(A) -> B,
initialValue: A
): Pair<View, StateFlow<B>> {
val root = LinearLayout(context)
@Sintrastes
Sintrastes / gdal_nix_log.txt
Created October 27, 2022 22:26
Error building gdal with nix on nixpkgs 22.05
This file has been truncated, but you can view the full file.
this derivation will be built:
/nix/store/hrgl9q3hcmf4nzfqf8b30mgx2ij63wnj-gdal-3.4.2.drv
building '/nix/store/hrgl9q3hcmf4nzfqf8b30mgx2ij63wnj-gdal-3.4.2.drv'...
Sourcing pytest-check-hook
Using pytestCheckPhase
unpacking sources
unpacking source archive /nix/store/cajis01pxh1dx0cxkpjsr7gbfyzm8bfz-source
source root is source/gdal
patching sources
autoreconfPhase
@Sintrastes
Sintrastes / Api.kt
Created March 6, 2022 20:38
Example showing how to decouple interface from implementation in an example from Robert Martin using generics.
package com.myorg.myapp.api
data class AlbumData(
val title: String,
val released: DateTime,
val artist: String
)
interface AlbumService {
suspend fun getAlbums(): List<AlbumData>
@Sintrastes
Sintrastes / CertifiedCleanSevenDaysAWeek.hs
Created February 27, 2022 18:09
Sketch of an idea to use graded categories to enforce the clean architecture at compile-time.
{-# LANGUAGE DataKinds, KindSignatures, TypeOperators, TypeFamilies #-}
module Main where
{-
Fun with graded categories and lattices: Enforcing the
Clean Architecute at compile time.
Alternate sub-title:
Certified clean, seven days a week
@Sintrastes
Sintrastes / DialogComonad.hs
Created January 30, 2022 23:19
Example of using a comonadic like structure to build a dialog tool.
-- class KComonad m w where
-- extractM :: w a -> m a
-- extendM :: (w a -> m b) -> w a -> m (w b)
-- duplicateM :: w a -> m (w (w a))
-- A variation on the Moore comonad
-- that allows for a termination condition.
-- Q: What kind of structure is this?
-- I think this is a monadic comonad with additional
@Sintrastes
Sintrastes / Assets.scala
Created January 16, 2022 02:41
Loading clips from Assets in Indigo.
List(Assets.Clips.NpcUp, Assets.Clips.NpcDown, Assets.Clips.NpcLeft, Assets.Clips.NpcRight)
.traverse(assetName => for
json <- assetCollection.findTextDataByName(assetName)
sprite <- Json.asepriteFromJson(json)
res <- sprite.toClips(assetName)
yield res
)
@Sintrastes
Sintrastes / DSL.scala
Created January 8, 2022 17:01
Game DSL example
def test(player1: Player, player2: Player) = gameAction {
transaction(
give = MyItem,
from = player1,
to = player2
)
startDialog {
speak(player1, "Thanks a lot!")
@Sintrastes
Sintrastes / DataKinds.kt
Last active November 21, 2021 16:12
Higher kinded types examples in Kotlin.
//
// Example of what non-"Type" kinded HKTs might look like in
// Kotlin with support for HKTs via a compiler plugin
//
sealed interface Nat<N: Nat<N>>
data class S<N: Nat<N>>(val pred: N): Nat<S<N>>
object Z: Nat<Z>
@Sintrastes
Sintrastes / Serialization.scala
Created November 2, 2021 14:16
Example of compile-time resolution of serializers/deserializers in a language with subtype polymorphism (Scala 3).
// Example serializable trait to mimic
// Kotlin @Serializable behavior from
// kotlinx serialization.
trait Serializable[A]:
def serialize(x: A): String
def deserialize(raw: String): Option[A]
class MyClass(val x: Int)
@Sintrastes
Sintrastes / Comonads.cpp
Created October 21, 2021 12:58
Comonads in C++.
//
// Comonads.cpp: Comonads in C++
//
// Author: Nathan Bedell
//
//
// "Your scientists were so preoccupied with whether or not they could, they didn't stop
// to think if they should."
//