Skip to content

Instantly share code, notes, and snippets.

object prizeranking {
def main(args: Array[String]): Unit = {
data.All
.map { prize =>
(prize, PrizeScore(prize))
}
.sortBy(-_._2)
.zipWithIndex
@cranst0n
cranst0n / PostGISCodec.scala
Created August 18, 2021 15:17
Skunk PostGIS codecs.
// Copyright (c) 2018-2021 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT
package skunk
package codec
import cats.Eq
import cats.syntax.all._
import skunk.data.Type
@cranst0n
cranst0n / retry.dart
Created January 4, 2022 18:43
dartz Task retry
part of dartz;
/// Mostly complete port of cats-retry to dartz.
class RetryStatus {
/// Retries attempted thus far.
final int retriesSoFar;
/// Total delay between successive retries.
final Duration cumulativeDelay;
@cranst0n
cranst0n / wordle.scala
Created May 9, 2022 13:19
Scala 3 wordle recommender
import cats.effect.ExitCode
import cats.effect.IO
import cats.effect.std.Console
import cats.syntax.all.*
import com.monovore.decline.Opts
import com.monovore.decline.effect.CommandIOApp
import fs2.io.file.Files
import fs2.io.file.Path
@cranst0n
cranst0n / CachedResource-Blog.md
Created March 26, 2024 17:19 — forked from Daenyth/CachedResource-Blog.md
CachedResource for cats-effect

Concurrent resource caching for cats

Motivation

cats-effect Resource is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:

trait Resource[F[_], A] {
  /** - Acquire resource
    * - Run f
 * - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails
@cranst0n
cranst0n / nexus.log
Created July 9, 2025 12:50
Relevant nexus error log when attempting to proxy Cargo
2025-07-08 11:25:35,911-0400 INFO [qtp464276110-1015] *UNKNOWN org.sonatype.nexus.repository.httpclient.internal.HttpClientFacetImpl - Repository status for cratesdotio changed from READY to AUTO_BLOCKED_UNAVAILABLE until 2025-07-08T11:26:15.911-04:00 - reason java.net.UnknownHostException: index.crates.io: Name or service not known for https://index.crates.io
2025-07-08 11:25:35,912-0400 WARN [qtp464276110-1015] *UNKNOWN com.sonatype.nexus.repository.cargo.internal.proxy.CargoProxyFacet - Failed to fetch config.json from remote
java.net.UnknownHostException: index.crates.io: Name or service not known
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:934)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533)
a