Skip to content

Instantly share code, notes, and snippets.

View rzeigler's full-sized avatar

Ryan Zeigler rzeigler

  • S5 Stratos
  • Plano, TX
View GitHub Profile
import cats.Monad
import cats.syntax.all._
import scala.collection.immutable.SortedMap
final case class MatrixVar(elem: String, map: SortedMap[String, String]) {
def render: String = {
val parts = map.toList.map(pair => show"${pair._1}=${pair._2}").intercalate(";")
show"$elem;$parts"
}
private def detectStall[F[_]: Concurrent: Timer, A]: Pipe[F, A, A] = {
val currentTime = Sync[F].delay(OffsetDateTime.now())
(stream: Stream[F, A]) =>
Stream.eval(currentTime).flatMap { startTime =>
Stream.eval(Ref[F].of(startTime)).flatMap { lastChunkSeen =>
val watchdog = Stream
.fixedRate(30.seconds)
.evalMap(_ => (currentTime, lastChunkSeen.get).tupled)
.ensure(new RuntimeException("pipeline appears to have stalled"))({
case (now, lastChunk) =>
@rzeigler
rzeigler / reader-task-example.ts
Created June 25, 2019 14:02
Using ReaderTaskEither from fp-ts
import * as http from "http";
import { ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither"
import { TaskEither, fromIO } from "fp-ts/lib/TaskEither";
import { IO } from "fp-ts/lib/IO";
import { Task } from "fp-ts/lib/Task";
import axios, { AxiosInstance } from 'axios';
import { Either, left, right } from "fp-ts/lib/Either";
export type Logger = (s: string) => TaskEither<never, void>;
@rzeigler
rzeigler / parallel-client.scala
Last active March 21, 2019 19:59
various ways of issuing requests
package com.github.rzeigler.reqs
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import org.http4s.client.blaze._
import org.http4s.client._
import org.http4s.Uri
import cats.temp.par._
@rzeigler
rzeigler / .hyper.js
Created July 7, 2017 17:24
.hyper.js for issue
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
@rzeigler
rzeigler / TerminalIO.hs
Last active September 12, 2016 17:40
Translation of https://github.com/tpolecat/examples/blob/master/src/main/scala/eg/FreeMonad.scala FreeMonad example to Haskell as well as an example program.
import Control.Monad.Free
import Control.Monad.State.Lazy
data TerminalOp a = ReadLine (String -> a) | WriteLine String a
instance Functor TerminalOp where
fmap f (ReadLine g) = ReadLine (f . g)
fmap f (WriteLine s a) = WriteLine s (f a)
type TerminalIO a = Free TerminalOp a