Skip to content

Instantly share code, notes, and snippets.

View andimiller's full-sized avatar

Andi Miller andimiller

View GitHub Profile
import scala.scalanative.unsafe.*
import scala.scalanative.unsigned.*
// Raw bindings
@link("sodium")
@extern
object libsodium {
def sodium_init(): CInt = extern
package net.andimiller.examples.htmx
package chat
import cats.implicits._
import cats.effect._
import org.http4s.{FormDataDecoder, HttpRoutes}
import org.http4s.dsl.Http4sDsl
import HTML._
import org.http4s.FormDataDecoder.{field, formEntityDecoder}
-- Represents a chainable functional stream
-- mutable versions of methods are available under .mutate
function Stream(tbl)
stream = { values = tbl, mutate = {} }
function stream.mutate.map(f)
transform(stream.values, f)
return stream
end
function stream.map(f)
stream.values = map(stream.values, f)
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
local gfx <const> = playdate.graphics
-- playdate.display.setScale(2)
tiles = gfx.imagetable.new('tiles/farm')
import cats.parse.Parser
import cats.implicits.*
import cats.*
import higherkindness.droste.*
object Calculator extends App:
// normal expression data structure
enum Expr:
case Add(a: Expr, b: Expr)
case Mul(a: Expr, b: Expr)
/*
name := "circe-droste-parser"
version := "0.1"
scalaVersion := "2.12.8"
libraryDependencies += "io.circe" %% "circe-rs" % "0.12.3"
libraryDependencies += "io.circe" %% "circe-literal" % "0.12.3"
libraryDependencies += "io.circe" %% "circe-parser" % "0.12.3"
import java.util.function.Function;
import java.util.Optional;
class Result<L, R> {
enum State {
Left,
Right
}
private final State state;
@andimiller
andimiller / sized.scala
Created October 19, 2018 16:51
sized decoder for http4s
case class Sized[T](bytes: Long, value: T)
object Sized {
implicit def sizedEntityDecoder[F[_] : FlatMap, T](implicit dec: EntityDecoder[F, T], F: Sync[F]): EntityDecoder[F, Sized[T]] =
new EntityDecoder[F, Sized[T]] {
override def decode(msg: Message[F], strict: Boolean): DecodeResult[F, Sized[T]] = {
EitherT(
for {
counter <- F.delay {
new LongAdder()
object TypeSafeBuilder {
sealed trait BuilderStatus
object Satisfied extends BuilderStatus
object NotSatisfied extends BuilderStatus
case class Cat(name: String, age: Int)
object CatBuilder {
def apply() = new CatBuilder[NotSatisfied.type, NotSatisfied.type](None, None)
/**
A quick example of practical GADT use in Dotty
val dottyVersion = "0.7.0-RC1"
val scala212Version = "2.12.4"
lazy val root = (project in file(".")).
settings(
name := "dotty-cross",
version := "0.1.0",