Skip to content

Instantly share code, notes, and snippets.

View rossabaker's full-sized avatar

Ross A. Baker rossabaker

View GitHub Profile
/.scala-build/
@rossabaker
rossabaker / openpgp.md
Created November 3, 2022 05:22
OpenPGP fingerprint URI

openpgp4fpr:904c153733dbb0106915c0bd975be5bc29d92ca5

import cats.Monad
import cats.StackSafeMonad
import cats.data.Kleisli
import cats.data.OptionT
import cats.effect.MonadCancel
import cats.effect.Resource
final class Routes[F[_], A, B] private (val run: A => Resource[F, Option[B]]) {
def map[C](f: B => C): Routes[F, A, C] =
Routes(run(_).map(_.map(f)))
// httpApp and dispatcher are required
// asyncTimeout and chunkSize have defaults
// Builder[F[_]] with constructor args
AsyncHttp4sServlet
.builder[IO](httpApp, dispatcher)
.withAsyncTimeout(5.seconds)
.withChunkSize(4096)
.build
@rossabaker
rossabaker / default.nix
Last active May 2, 2022 18:17
Input From Derivation hijinks
{ config, pkgs, ... }:
let
# In the real world, this is an org tangle.
hello = pkgs.writeText "hello" ''
{ pkgs, ... }: {
home.packages = [ pkgs.hello ];
}
'';
//> using scala "2.13"
//> using lib "com.armanbilge::bayou:0.1-4fb42c8"
//> using lib "org.typelevel::cats-effect:3.3.7"
//> using lib "co.fs2::fs2-core:3.2.5"
//> using lib "org.typelevel::log4cats-core:2.2.0"
//> using lib "org.typelevel::log4cats-slf4j:2.2.0"
//> using lib "org.tpolecat::natchez-core:0.1.6"
//> using lib "org.tpolecat::natchez-log:0.1.6"
import cats.effect.{Trace => _, _}
import $ivy.`org.typelevel::munit-cats-effect-3:1.0.7`
import $ivy.`org.tpolecat::natchez-mock:0.1.6`
import $ivy.`co.fs2::fs2-core:3.2.5`
import cats.data.Kleisli
import cats.effect.Deferred
import cats.effect.IO
import cats.effect.IOLocal
import cats.effect.MonadCancelThrow
import cats.effect.Resource
@rossabaker
rossabaker / set_map.scala
Created February 5, 2022 04:37
Set is not a functor
scala> import org.typelevel.ci._
import org.typelevel.ci._
scala> val f: String => CIString = CIString.apply
val f: String => org.typelevel.ci.CIString = $Lambda$1025/2055291664@4bbf38b8
scala> val g: CIString => String = _.toString
val g: org.typelevel.ci.CIString => String = $Lambda$1027/1152113439@62108cd3
scala> val rosses = Set("Ross", "ROSS", "ross") // three too many if you ask me
import cats._
// A pure functional, contravariant monoidal string builder
sealed trait SB[A] {
final def render(a: A): String = {
val sb = new StringBuilder
renderInternal(sb, a)
sb.toString
}
(use-package lsp-haskell
:config
(setq lsp-haskell-process-path-hie "haskell-language-server-wrapper")
;; xref backends don't compose. This creates one that first consults the
;; xref-lsp backend for the latest information from the language server,
;; and then falls through to etags for library definitions.
(defun my/xref-lsp-etags-backend () 'my/lsp-etags)
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql my/lsp-etags)))
(xref-backend-identifier-at-point 'xref-lsp))