Skip to content

Instantly share code, notes, and snippets.

import BasicAuthAlgebra.Credentials
trait Algebra {
type Endpoint[Req, Resp]
type Request[T]
type RequestHeaders[T]
type Path[T]
type RequestBody[T]
type Method
type Response[T]
import java.io._
import io.circe._
import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.language.higherKinds
import scala.util.{Failure, Success, Try}
trait Codec[T] {
//simplified logger from scala-logging
trait LoggerTakingImplicit[T] {
def log(msg: String)(implicit ev: CanLog[T])
}
trait CanLog[T] {
def logMessage(originalMsg: String, a: T): String
}
import magnolia._
object MagnoliaTest {
trait TCA[T] {
def showA: String
}
trait TCB[T] {
def showB: String
}
trait PostgresExtension {
val ctx: QuillCtx
import ctx._
implicit val jsonDecoder: Decoder[JsonObject] =
decoder(
(index, row) =>
io.circe.parser.decode[JsonObject](row.getObject(index).toString) match {
case Left(failure) => throw failure
@Krever
Krever / hkt-crud.scala
Created February 29, 2020 20:09
Higher kinded data for CRUD
sealed trait RelationUpdate[+New, +Id]
object RelationUpdate {
type Aux[E <: EntityBase] = RelationUpdate[E#New, E#Id]
case class CreateAndAdd[New](items: List[New]) extends RelationUpdate[New, Nothing]
case class Delete[Id](items: List[Id]) extends RelationUpdate[Nothing, Id]
case class Add[Id](items: List[Id]) extends RelationUpdate[Nothing, Id]
}
object H {
case class UIO[T](x: () => T) // ZIO
@Krever
Krever / howto.md
Created March 30, 2020 06:04
How to use windows keyboard on macOS

The goal is to use the same external keyboard (and so the same muscle memory) for both linux and macOS

  1. Swap CMD and CTRL in macOS keyboard settings (can be done only for external keyboard)
  2. Swap back the modifier for iTerm (so ctrl is cmd for all other apps but stays ctrl for iTerm)

Remaining problems:

  • navigate by word - ctrl+arrows on linux, alt+arrows on mac
@Krever
Krever / MyXMLParser.scala
Created May 7, 2020 12:33
Make sax parser offline
object MyXMLParser extends XMLLoader[Elem] {
override def parser: SAXParser = {
val f = javax.xml.parsers.SAXParserFactory.newInstance()
f.setNamespaceAware(false)
f.setValidating(false)
f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
f.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
f.newSAXParser()
}
@Krever
Krever / newsubtype.ts
Created July 4, 2020 18:37
Newsubtypes in TS
type Tag = { readonly __tag: symbol }
export type NewSubtype<Base, Tagg extends Tag> = Base & Tagg;
export type NewSubtypeCompanion<T extends NewSubtype<E, Tagg>, E = any, Tagg extends Tag = any> = {
create: (_: E) => NewSubtype<T, Tagg>
}
export const createNewtypeCompanion: <T extends NewSubtype<E, Tagg>, E = any, Tagg extends Tag = any>() => NewSubtypeCompanion<T, E> =
<T extends NewSubtype<E, Tagg>, E, Tagg extends Tag>() => ({
create: (x: E) => x as NewSubtype<T, Tagg>
})

Keybase proof

I hereby claim:

  • I am krever on github.
  • I am krever (https://keybase.io/krever) on keybase.
  • I have a public key ASC1x_RoDw8-jOLQX9Nahjjgp27psX9vMXcWNynYt4PKjwo

To claim this, I am signing this object: