Skip to content

Instantly share code, notes, and snippets.

@scalway
scalway / tapir-zio-dynamic-api.sc
Created April 15, 2024 10:36 — forked from dacr/tapir-zio-dynamic-api.sc
An API to rule them all - to define or customize new API at runtime / published by https://github.com/dacr/code-examples-manager #dbccfc26-c532-4aa9-b3cd-eb13cbaa5370/764dc89bc8faf304aa6e1a5394904ae8cca6d0e4
// summary : An API to rule them all - to define or customize new API at runtime
// keywords : scala, zio, tapir, http, zhttp, stateful, state, @testable, @exclusive
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : dbccfc26-c532-4aa9-b3cd-eb13cbaa5370
// created-on : 2023-12-08T18:45:32+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// test-with : curl -L http://127.0.0.1:8080/hello/david
//> using scala 3
//> using dep com.lihaoyi::fansi:0.4.0
import scala.io.StdIn.readLine
import java.util.Arrays
case class Pos(val x: Int, val y: Int)
object Pos:
def fromUserInput(indexes:Seq[Int]): Option[Pos] = indexes match
@scalway
scalway / watchDiff.scala
Last active August 4, 2023 09:49
scala ammonite script that implement `watch -d ""` that shows only diffs. I was using it to see changes in `lsof -p SOMEPROCID` to watch if there are any leaks in my app.
//> using toolkit latest
//> using dep io.github.java-diff-utils:java-diff-utils:4.12
//> using dep com.lihaoyi::fansi::0.4.0
// use like this: scala-cli run . -- 200 lsof -p 28482
import com.github.difflib.*
import com.github.difflib.patch.*
import fansi.*
import os.*
@scalway
scalway / web-audio-fetch-stream.js
Last active January 31, 2019 11:13 — forked from revolunet/web-audio-fetch-stream.js
Web Audio streaming with fetch API
//
// loads remote file using fetch() streams and "pipe" it to webaudio API
// remote file must have CORS enabled if on another domain
//
// mostly from http://stackoverflow.com/questions/20475982/choppy-inaudible-playback-with-chunked-audio-through-web-audio-api
//
function play(url) {
var context = new (window.AudioContext || window.webkitAudioContext)();
@scalway
scalway / gist:07cc13a4c6b20025c001d3d71ac137b5
Last active October 2, 2018 13:20
scalajs-compilation-error-dashboard.txt
[info] Full optimizing /app-server/app-dashboard/target/scala-2.11/app-dashboard-opt.js
[debug] Linker: Compute reachability: 827080 us
java.lang.StackOverflowError
at org.scalajs.core.ir.Serializers$Deserializer.readTree(Serializers.scala:686)
at org.scalajs.core.ir.Serializers$Deserializer.readTreeFromTag(Serializers.scala:750)
at org.scalajs.core.ir.Serializers$Deserializer.readTree(Serializers.scala:687)
at org.scalajs.core.ir.Serializers$Deserializer.readTreeFromTag(Serializers.scala:752)
at org.scalajs.core.ir.Serializers$Deserializer.readTree(Serializers.scala:687)
at org.scalajs.core.ir.Serializers$Deserializer$$anonfun$readTrees$1.apply(Serializers.scala:928)
at org.scalajs.core.ir.Serializers$Deserializer$$anonfun$readTrees$1.apply(Serializers.scala:928)
java.lang.StackOverflowError
at scala.reflect.internal.Types$Type.isStable(Types.scala:271)
at scala.tools.nsc.typechecker.Typers$Typer.expectsStable$1(Typers.scala:507)
at scala.tools.nsc.typechecker.Typers$Typer.isStableContext(Typers.scala:514)
at scala.tools.nsc.typechecker.Typers$Typer.typedThis$1(Typers.scala:4702)
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5374)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5387)
at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:712)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5423)
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5450)
@scalway
scalway / UPickleMagnoliaDerive.scala
Last active June 28, 2018 10:32
UPickle Magnolia Derive
package rabbi
import magnolia._
import ujson.{ObjVisitor, Visitor}
import upickle.{Api, AttributeTagged}
import scala.language.experimental.macros
import scala.reflect.ClassTag
trait UpickleSupportCommon {
@scalway
scalway / MagnoliaDefault.scala
Created April 27, 2018 11:02
Magnolia - more complicated Default example
package example
/* Magnolia, version 0.7.1. Copyright 2018 Jon Pretty, Propensive Ltd.
*
* The primary distribution site is: http://co.ntextu.al/
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
trait DefaultModule extends mill.scalalib.ScalaModule {
//def scalaVersion = "2.12.4"
//def scalaJSVersion: T[String] = "0.6.22"
}
def main() = ()
@scalway
scalway / Bootstrap3.scala
Last active May 19, 2018 19:06
bootstrap3 scalatags pug'like heler.
/**
* Copyright 2017 Scalway Krzysztof Pecyna
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,