Skip to content

Instantly share code, notes, and snippets.

@megri
megri / build.sc
Last active May 10, 2024 11:41
Scala cli-style inline deps declarations for mill
import mill._, scalalib._
object MyModule extends ScalaModule {
def inlineIvyDeps = T {
def parseDep(usingDepClause: String): Dep = {
val part = usingDepClause.drop("//> using dep ".size)
if (part.startsWith("\"")) Dep.parse(part.tail.init.trim)
else Dep.parse(part.trim)
}
@megri
megri / build.sc
Created March 27, 2024 20:58
Mill-driven hot-reload for Indigo
import mill._, scalalib._, scalajslib._
import scala.collection.mutable
object ElectronModule {
class Worker(val dstBase: os.Path) extends AutoCloseable {
private val updateTimes = mutable.Map[os.Path, Long]()
private var process: os.SubProcess = null
@megri
megri / app-root: index.html
Last active March 24, 2024 08:29
Simple Indigo config with hot reloading
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
<meta charset="UTF-8">
<title>Hello, Indigo!</title>
<style>
body {
padding: 0;
override def run(args: List[String]): IO[ExitCode] = {
val databaseConfig = DatabaseConfig(
host = "localhost",
port = 5432,
username = "postgres",
database = "postgres",
password = None,
strategy = Strategy.SearchPath,
debug = true
)
import cats.effect._
import cats.implicits._
import com.twitter.finagle.{Http, ListeningServer}
import doobie._
import doobie.hikari._
import io.catbird.util._
import io.catbird.util.effect._
object App extends IOApp {
val transactor: Resource[IO, HikariTransactor[IO]] = {
import com.lightbend.lagom.scaladsl.playjson.JsonSerializer
import reflect.macros._
object JsonSerializerImpl {
/**
* Generates a list of JsonSerializers for all direct subtypes of type T. Every subtype needs an implicit Format[T]
* in scope at the place of expansion.
* @param c
* @tparam T
@megri
megri / gist:b416ffc67de1c6e25d521a680eb43dc8
Created November 16, 2018 12:40
sbt -Dsbt.log.noformat=true scalafix > scalafix-log
[info] Updating facebookApi...
[info] Updating userSearchApi...
[info] Updating ...
[info] Updating auth...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies.
[warn] Run 'evicted' to see detailed eviction warnings
[info] Updating accountApi...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies.

Reworked proposal for unification of package, object and package object

Keyword changes

  • object becomes module
  • package becomes module
  • package object becomes module
  • Support for top-level definitions

Syntax changes

import cats.syntax.apply._
import io.circe._
import io.circe.literal._
object JsonValidation{
def validate[A: Decoder]( f: HCursor => ACursor, pred: A => Boolean, err: A => String ): Decoder[A] =
Decoder.instance(
f andThen{ ac =>
ac.as[A].flatMap( a =>
if ( pred( a ) )
object Rational {
implicit def rationalInt(n: Int): Rational =
Rational(n, 1)
def gcd(a: Int, b: Int): Int =
if (b == 0) a else gcd(b, a % b)
}
case class Rational(p: Int, q: Int) {
require(q != 0, "Denominator 'q' cannot be 0")