Skip to content

Instantly share code, notes, and snippets.

View mikla's full-sized avatar

Artsiom Miklushou mikla

View GitHub Profile
@neubig
neubig / dispatch_openai_requests.py
Last active February 19, 2024 17:55
A simple script to get results from the OpenAI Asynchronous API
# NOTE:
# You can find an updated, more robust and feature-rich implementation
# in Zeno Build
# - Zeno Build: https://github.com/zeno-ml/zeno-build/
# - Implementation: https://github.com/zeno-ml/zeno-build/blob/main/zeno_build/models/providers/openai_utils.py
import openai
import asyncio
from typing import Any

Understanding Comparative Benchmarks

I'm going to do something that I don't normally do, which is to say I'm going to talk about comparative benchmarks. In general, I try to confine performance discussion to absolute metrics as much as possible, or comparisons to other well-defined neutral reference points. This is precisely why Cats Effect's readme mentions a comparison to a fixed thread pool, rather doing comparisons with other asynchronous runtimes like Akka or ZIO. Comparisons in general devolve very quickly into emotional marketing.

But, just once, today we're going to talk about the emotional marketing. In particular, we're going to look at Cats Effect 3 and ZIO 2. Now, for context, as of this writing ZIO 2 has released their first milestone; they have not released a final 2.0 version. This implies straight off the bat that we're comparing apples to oranges a bit, since Cats Effect 3 has been out and in production for months. However, there has been a post going around which cites various compar

  1. def hash(a: A): Int makes me sad. What about hashing to 64 bits or SL2 Fp?
  2. def MapHash[A, B: Hash]: Hash[Map[A, B]] is a bit odd. Why not A: Hash?
  3. reflexiveLaw + symmetryLaw + transitivityLaw is too weak for "equality". This defines a general equivalence relationship only.
  4. val AnyEqual: Equal[Any] is worrisome, considering all the resolution bugs!
  5. val DoubleEqual: Equal[Double] should be implemented using java.lang.Double.doubleToRawLongBits.
  6. A combintation of [trait Ord[-A] extends Equal[A]](https://github.com/zio/zi
@japgolly
japgolly / copy.sbt
Last active October 1, 2019 12:22
Scala.JS & SBT
// Assumptions:
// 1. You have one or more Scala.JS modules named jsModule1, jsModule2, ...
// 2. You have a web-serving (or otherwise JVM) module that will serve the JS assets
// The only "webby"/JS plugin I use apart from Scala.JS itself, is xsbt-web-plugin,
// and even that, only on my pre-http4s projects.
// xsbt-web-plugin allows me to quickly stop/start a servlet container from SBT.
// The snippet below is for "webappPostProcess" which is an xsbt-web-plugin task but
// if you aren't using it, you can just create a task with the same content and make
// "package" depend on it.
@japgolly
japgolly / 0.deps.gv.svg
Last active April 2, 2020 23:40
My Scala libraries & the status of their upgrade to Scala 2.13
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@dcastro
dcastro / shapeless-fieldname.scala
Last active July 13, 2021 20:01
Shapeless - get a field's name in a type-safe way
import shapeless._
import shapeless.ops.record.Keys
import shapeless.ops.hlist.Selector
import shapeless.tag._
/**
* Gets the name of a case class's field, in a type-safe way.
* If the class does not have a field with the given name, the program won't compile.
*
* Kinda similar to C#'s `nameof` operator, but not bolted onto the language
@Tvaroh
Tvaroh / collectFirst.scala
Last active January 11, 2018 13:26 — forked from Odomontois/collectFirst.scala
collectFirstM using cats
import cats.implicits._
object CollectFirstM {
implicit class CollectFirstMSyntax[F[_], A](val xs: Seq[A]) extends AnyVal {
def collectFirstM[B, M[_]](f: A => M[Option[B]])(implicit M: Monad[M]): M[Option[B]] =
M.tailRecM(xs) {
case x +: rest => f(x).map {
case some@Some(_) => Right(some)

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@mielientiev
mielientiev / SlickFinalTaggless.scala
Last active February 5, 2019 21:20
Slick Final Tagless approach
// build.sbt
val slick = Seq(
"com.typesafe.slick" %% "slick" % "3.2.1",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.typesafe.slick" %% "slick-hikaricp" % "3.2.1",
"com.h2database" % "h2" % "1.4.196"
)
val scalaz = Seq(
"org.scalaz" %% "scalaz-core" % "7.2.17"
)