Skip to content

Instantly share code, notes, and snippets.

View hamnis's full-sized avatar

Erlend Hamnaberg hamnis

View GitHub Profile
import java.util.UUID
import java.security.SecureRandom
import java.time.Instant
object UUIDV7 {
lazy val defaultRandom = new SecureRandom()
def create: UUID = create(defaultRandom)
def create(rnd: SecureRandom): UUID = create(rnd, System.currentTimeMillis)
//> using scala "3.2.2"
//> using lib "com.softwaremill.sttp.tapir::tapir-core:1.2.8"
package issue
import sttp.tapir.Schema
object Test {
enum Type {
case STRING
@hamnis
hamnis / Readme.md
Last active July 31, 2023 05:12
place start-bloop.sh in /usr/local/bin and bloop.json in project_root_dir/.bsp/bloop.json

Installation

place start-bloop.sh in /usr/local/bin

make it executable:

chmod 755 /usr/local/bin/start-bloop.sh

Project installation

package reloadable
import cats.effect._
import cats.syntax.all._
import org.typelevel.log4cats.LoggerFactory
import java.io.ByteArrayInputStream
import java.net.Socket
import java.nio.charset.StandardCharsets
import java.security.KeyStore
java.lang.NullPointerException: null
at java.base/sun.net.util.IPAddressUtil.textToNumericFormatV4(IPAddressUtil.java:49)
at java.base/sun.net.util.IPAddressUtil.isIPv4LiteralAddress(IPAddressUtil.java:241)
at java.base/sun.security.util.HostnameChecker.isIpAddress(HostnameChecker.java:117)
at java.base/sun.security.util.HostnameChecker.match(HostnameChecker.java:95)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:459)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:434)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:291)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:141)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:620)
import cats.implicits._
import cats.MonadError
import cats.data.{Kleisli, OptionT}
import org.http4s._
object ErrorHandling {
def apply[F[_], G[_]](
k: Kleisli[F, Request[G], Response[G]],
pf: Request[G] => PartialFunction[Throwable, F[Response[G]]] = inDefaultServiceErrorHandler[F, G]
@hamnis
hamnis / ContentNegotiation.scala
Created February 1, 2021 07:16
Content-Negotiation for http4s
import org.http4s.{MediaType, MediaRange, Request, Response}
import org.http4s.headers.{Accept, MediaRangeAndQValue}
import cats.data.NonEmptyList
import org.http4s.QValue
/*
* https://tools.ietf.org/html/rfc7231#section-5.3
*/
object ContentNegotiation {
@hamnis
hamnis / SseClient.scala
Last active August 26, 2020 08:23 — forked from izeigerman/SseClient.scala
Complete SSE client Implementation for Scala using http4s.
import cats.effect.Timer
import fs2.{Pull, RaiseThrowable, Stream}
import org.http4s._
import org.http4s.ServerSentEvent.EventId
import org.http4s.client.Client
import org.http4s.headers.{Accept, `Cache-Control`}
import scala.concurrent.duration._
import SseClient._
package com.example.http4s
import cats.data.OptionT
import cats.effect.Sync
import org.http4s.dsl.impl.Path
import org.http4s.headers.Allow
import org.http4s.{AuthedRoutes, HttpRoutes, Method, Response, Status}
object Route {
def of[F[_]: Sync](pf: PartialFunction[Path, Map[Method, HttpRoutes[F]]]): HttpRoutes[F] = HttpRoutes[F] { req =>
package xmldecoder
import scala.util.Try
import scala.xml.{Node, NodeSeq}
case class XMLDecodeException(path: String, message: String) extends Exception {
override def getMessage: String = s"[$path] - $message"
}
trait Decoder[A] {