Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
object prizeranking {
def main(args: Array[String]): Unit = {
data.All
.map { prize =>
(prize, PrizeScore(prize))
}
.sortBy(-_._2)
.zipWithIndex
// Installed Extensions:
// - Scala Syntax (Dalton Jorge)
// - Git History (Don Jayamanne)
// - File Utils (Steffen Leistner)
// - Material Theme (Mattia Astorino)
// - Subword Navigation (Steffen Leistner)
//////////////////// settings.json ////////////////////
@cranst0n
cranst0n / keybase.md
Created February 28, 2017 14:57
Keybase

Keybase proof

I hereby claim:

  • I am cranst0n on github.
  • I am cranston (https://keybase.io/cranston) on keybase.
  • I have a public key ASBmaO4BDTwDgCEWyqF2XHWg0VbivsjJSXfk6390CoUpawo

To claim this, I am signing this object:

# Taken from 'http://stackoverflow.com/questions/750172/change-the-author-of-a-commit-in-git'
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
then
GIT_COMMITTER_NAME="<New Name>";
GIT_AUTHOR_NAME="<New Name>";
GIT_COMMITTER_EMAIL="<New Email>";
GIT_AUTHOR_EMAIL="<New Email>";
git commit-tree "$@";
else
@cranst0n
cranst0n / repositories
Created March 15, 2016 18:44
Sample repositories file to get SBT working with Artifactory
# Use '-Dsbt.override.build.repos=true' and '-Dsbt.repository.config=repositories' flags when firing up SBT
[repositories]
local
ivy-proxy: http://192.168.2.107:8081/artifactory/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-proxy: http://192.168.2.107:8081/artifactory/repo/
sbt-plugins-proxy: http://192.168.2.107:8081/artifactory/repo/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
package freedom
import java.awt.{ Color, Graphics2D }
import java.awt.image.BufferedImage
import cats.data.Coproduct
import cats.free.{ Free, Inject }
import cats.{ ~>, Id }