Skip to content

Instantly share code, notes, and snippets.

View gatorcse's full-sized avatar

Tristan Lohman gatorcse

  • Port Angeles, WA
  • 04:53 (UTC -07:00)
View GitHub Profile
@gatorcse
gatorcse / EmberBroken.scala
Last active July 1, 2020 22:24
Ember combined with Natchez hangs on large responses.
package emberbroken
import cats._
import cats.data.Kleisli
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import natchez.{EntryPoint, Span, Trace}
import org.http4s._
import org.http4s.client.blaze.BlazeClientBuilder
@gatorcse
gatorcse / StreamMerger.scala
Last active January 14, 2023 21:09
Merging two already sorted fs2 streams, with a sortBy function.
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import fs2._
class StreamMerger[F[_]] {
def priorityOrderBy[A, B: Order](s1: Stream[F, A], s2: Stream[F, A])(f: A => B): Stream[F, A] = {
def go(p1: Stream.StepLeg[F, A], p2: Stream.StepLeg[F, A]): Pull[F, A, Unit] = {
@gatorcse
gatorcse / SentenceMangle.scala
Last active August 29, 2015 14:27
Solves reddit challenge 220
package tlo.reddit
object SentenceMangle {
val sampleInputs = Seq(
"This challenge doesn't seem so hard.",
"There are more things between heaven and earth, Horatio, than are dreamt of in your philosophy."
)
val challengeInputs = Seq(
"Eye of Newt, and Toe of Frog, Wool of Bat, and Tongue of Dog.",
var Hoek = require('Hoek')
var defaults = {}
exports.register = function (plugin, options, next) {
options = Hoek.applyToDefaults(defaults, options)
plugin.route({
path: '/foo',
method: 'GET',
@gatorcse
gatorcse / AhoCorasick.scala
Created October 4, 2013 19:28
A basic implementation of Aho-Corasick in Scala. Not thread safe because the tree uses mutable state.
package com.tlo.ahocorasick
import scala.collection.mutable
import scala.collection.immutable
import scala.annotation.tailrec
sealed trait Node {
def children: mutable.Map[Char, LetterNode]
}