hey -z 30s http://localhost:8080/foo
Summary:
Total: 30.0004 secs
Slowest: 0.4091 secs
Fastest: 0.0001 secs
Average: 0.0015 secs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env catscript | |
// dependency: "org.http4s" %% "http4s-ember-server" % "1.0.0-M21" | |
// dependency: "org.http4s" %% "http4s-circe" % "1.0.0-M21" | |
// dependency: "org.http4s" %% "http4s-dsl" % "1.0.0-M21" | |
// dependency: "ch.qos.logback" % "logback-classic" % "1.2.3" | |
import org.http4s._ | |
import org.http4s.circe._ | |
import org.http4s.circe.middleware._ | |
import org.http4s.dsl.io._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"catscript": { | |
"repositories": [ | |
"central" | |
], | |
"dependencies": [ | |
"io.chrisdavenport::catscript:latest.release" | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sbt -Dsbt.version=1.5.0 -Dsbt.main.class=sbt.ScriptMain -Dsbt.supershell=false -error | |
// Note that `ScriptMain` doesn't work with Scala 3 yet, and won't unless a | |
// volunteer steps up: https://github.com/sbt/sbt/issues/6274 | |
/*** | |
scalaVersion := "2.13.5" | |
onLoadMessage := "" | |
scalacOptions ++= Seq( | |
"-deprecation", "-unchecked", "-feature", "-Werror") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait LiftF[M[_[_], _]]{ | |
def liftF[F[_], A](fa: F[A])(implicit ev: cats.Monad[F]): M[F, A] | |
} | |
object LiftF { | |
implicit class LiftOps[F[_], A](private val fa: F[A]){ | |
def liftF[M[_[_], _]](implicit ev1: LiftF[M], ev2: Monad[F]): M[F, A] = | |
ev1.liftF(fa) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BitInsanity { | |
def bitPositions(int: Int): List[Int] = { | |
val buffer = new scala.collection.mutable.ListBuffer[Int]() | |
var number = int | |
var position = 0 | |
while (number != 0){ | |
if ((number & 1) != 0) { | |
buffer.addOne(position) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credit to Hollow: https://github.com/Netflix/hollow/blob/b2890aab063b530b1cffe1af7b21d1358024c6e7/hollow/src/main/java/com/netflix/hollow/core/memory/ThreadSafeBitSet.java | |
import java.util.concurrent.atomic.AtomicLongArray | |
import java.util.concurrent.atomic.AtomicReference | |
import scala.util.control.Breaks | |
import scala.util.hashing.MurmurHash3 | |
import scala.collection.BitSet | |
import scala.collection.mutable | |
class ThreadSafeBitSet private ( | |
private final val numLongsPerSegment: Int, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect._ | |
trait Lock[F[_]]{ | |
def lock: F[Unit] | |
def unlock: F[Unit] | |
} | |
object Lock { | |
def fromLock[F[_]: Sync](jlock: java.util.concurrent.locks.Lock): Lock[F] = new Lock[F]{ | |
def lock: F[Unit] = Sync[F].blocking(jlock.lockInterruptibly()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats._ | |
import cats.syntax.all._ | |
import cats.effect._ | |
import cats.effect.concurrent._ | |
trait VolatileReadWrite[F[_], A]{ | |
def read: F[A] | |
def set(a: A): F[Unit] = write(_ => (a, ())) | |
def write[B](f: A => (A, B)): F[B] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect._ | |
// import cats._ | |
import cats.syntax.all._ | |
import scala.concurrent.duration._ | |
trait FakeIO[A]{ | |
def unsafeRunAsync(f: Either[Throwable, A] => Unit): Unit | |
} | |
object FakeIO { | |
def delay[A](thunk: => A): FakeIO[A] = Async{cb: (Either[Throwable, A]=> Unit) => cb(Either.catchNonFatal(thunk))} | |
def async[A](f: (Either[Throwable, A] => Unit) => Unit): FakeIO[A] = Async{cb => |