Skip to content

Instantly share code, notes, and snippets.

@Krever
Krever / wio.scala
Last active April 2, 2024 05:23
context-dependent-wio
// This is a very minimal example showcasing how we can levarage type members to capture fixed types without the need
// to introduce more type parameters
trait WorkflowContext {
type State
type Event
// operation that transforms In into Out, while guaranteeing the output is a substate os State
@Krever
Krever / README.md
Created June 4, 2023 19:42
Find Audible whishlist title worth buying.

Scripts are based on python audible lib, install accordign to docs: https://audible.readthedocs.io/en/latest/index.html

  1. Modify auth.py with your credentials
  2. Run auth.py - your creds will be saved in creds.txt for further calls
  3. Run dump_whishlist.py - your whishlist will be saved in whishslist.json
  4. Run filter-whishlist-for-sale.py - it will printout all titles below the credit price
@Krever
Krever / DotRenderer.scala
Last active April 21, 2023 06:41
Graphviz Dot AST
object DotRenderer {
def render(graph: Graph): String = {
graph match {
case DirectedGraph(strict, id, stmtList) =>
s"${if (strict) "strict " else ""}digraph ${id.getOrElse("")} {${renderStmtList(stmtList)}}"
case UndirectedGraph(strict, id, stmtList) =>
s"${if (strict) "strict " else ""}graph ${id.getOrElse("")} {${renderStmtList(stmtList)}}"
}
}
@Krever
Krever / _README.md
Last active March 9, 2024 16:21
Yabai setup for i3wm users

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:

@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>
})
@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 / 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 / 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
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