Skip to content

Instantly share code, notes, and snippets.

View kareblak's full-sized avatar

Kåre Blakstad kareblak

View GitHub Profile
@kareblak
kareblak / transformers.scala
Last active January 30, 2024 12:54
Transformations between `monix.NewtypeWrapped` and `smithy4s.Newtype` with ducktape
import smithy4s.ShapeId
import smithy4s.Bijection
import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.string
import io.github.arainko.ducktape.*
import monix.newtypes.*
import scala.Either
### Keybase proof
I hereby claim:
* I am kareblak on github.
* I am kareblak (https://keybase.io/kareblak) on keybase.
* I have a public key whose fingerprint is CF12 2596 B9CE F2FF AA37 3727 6CDA 282B 269B 1FA1
To claim this, I am signing this object:
@kareblak
kareblak / circe.scala
Last active October 10, 2018 10:57
could not find Lazy implicit value of type io.circe.generic.extras.decoding.Configured(Decoder|Encoder)[A]
sealed trait T
object T {
object X {
case class T1(foo: String)
case class T2(bar: String)
}
}
def lastB[A, B](implicit S:Strategy): Pipe2[Task, A, B, (A, B)] = (as, bs) =>
bs.uncons1.flatMap {
case None => Stream.empty
case Some((init, newBs)) =>
as.either(newBs).mapAccumulate(init) {
case (b, Left(a)) => (b, Some(a))
case (_, Right(b)) => (b, None)
}.collect { case (b, Some(a)) => (a, b) }
}
import fs2._
import org.http4s._
import org.http4s.dsl._
import org.http4s.server.blaze._
import org.http4s.server.websocket._
import org.http4s.util._
import org.http4s.websocket.WebsocketBits
import scala.concurrent.duration._
import fs2.async.mutable.Topic
{
"vessel_id": "259994000",
"vessel_name": "REBBENESOY",
"for_day": "2017-02-12",
"connections": [
{
"name": "188",
"total_time_in_traffic": {
"value": 5.130917777777778,
"unit": "hours"
def mappedIntent = Mapping[Any, String] {
case ContextPath(_, path) => path
}
def intent = mappedIntent {
case "/" => (get | post)
}
Error:(23, 22) type mismatch;
found : unfiltered.directives.FilterDirective[javax.servlet.http.HttpServletRequest,Any,unfiltered.response.ResponseFunction[Any]]
case class GetOrElseCachedValue[K, V](key: K, orElse: () => V)
case class GetCachedValue[K, V](key: K)
case class PutCachedValue[K, V](key: K, value: V)
case class ReturnCachedValue[V](value: Option[V])
case class RemoveCachedValue[K](key: K)
case object PurgeCachedValues
class CacheActor[K, V] private[cache](cache: Cache) extends Actor with ActorLogging with StatsD {
type FV = (() => V)
@kareblak
kareblak / sqlcreat0rz.scala
Last active December 5, 2016 14:47
Convert from MySQL area dump to PostGIS insert statements
import java.io.FileOutputStream
Console.withOut(new FileOutputStream("/Users/kareblak/Downloads/area.sql")) {
println(
scala.io.Source.fromFile("/Users/kareblak/Downloads/areas.csv").getLines.toList.tail.map(_.split(',')).groupBy {
case Array(_, n, _*) => n
}.map {
case (k, vs) => k -> vs.collect {
case Array(_, _, _, c) => c
}
useGpg := true
appAssemblerSettings
appOutput in App := target.value / "appmgr" / "root"
appmgrSettings
appmgrOutputFile in Appmgr := target.value / "%s-appmgr.zip".format(name.value)