Skip to content

Instantly share code, notes, and snippets.

View bryce-anderson's full-sized avatar

Bryce Anderson bryce-anderson

View GitHub Profile
sealed trait HeaderKey {
type HeaderT <: Parsed[_]
def go(t: HeaderT): Unit = ()
def name: String
}
/*
@bryce-anderson
bryce-anderson / twitter.scala
Created October 30, 2015 18:17
slapped together bits of a basic http4s interface to the Twitter streaming API. OAuth not included.
// a simple process1 that splits the frames up based on a "\r\n" sequence of chars
val partitioner = {
import java.util.regex.Pattern
import scalaz.stream.process1
import scalaz.std.string._
val pattern = Pattern.compile("\r\n")
process1.repartition { s: String =>
pattern.split(s, -1)
sealed abstract class JValue
final class JBoolean private(val value: Boolean) extends JValue
object JBoolean {
val True = new JBoolean(true)
val False = new JBoolean(false)
def apply(value: Boolean): JBoolean = if (value) True else False

Keybase proof

I hereby claim:

  • I am bryce-anderson on github.
  • I am brycelane (https://keybase.io/brycelane) on keybase.
  • I have a public key whose fingerprint is D795 F052 A43C 58AE 3A27 651E 0764 616F 7E54 47BC

To claim this, I am signing this object:

public int go2(org.http4s.client.blaze.Foo$Thing);
Code:
0: aload_1
1: astore_2
2: aload_2
3: instanceof #16 // class org/http4s/client/blaze/Foo$ThingA
6: ifeq 48
9: aload_2
10: checkcast #16 // class org/http4s/client/blaze/Foo$ThingA
13: astore_3
@bryce-anderson
bryce-anderson / nio.scala
Created December 15, 2014 20:45
scalaz-stream nio performance tuning
package scalaz.stream
import java.io._
import scodec.bits.ByteVector
import scalaz._, Scalaz._, stream._
import scalaz.stream.nio._
@bryce-anderson
bryce-anderson / ExampleRoute.scala
Last active December 30, 2015 05:09
Working challenge
case req@ Post -> Root / "challenge" =>
val body = req.body.collect {
case c: BodyChunk => new String(c.toArray)
}.toTask
body.flatMap{ s: String =>
if (!s.startsWith("go")) {
Ok("Booo!!!")
} else {
Ok(emit(s) ++ repeatEval(body))
@bryce-anderson
bryce-anderson / ContinuingParser.scala
Last active December 30, 2015 04:09
untested method for parsing a Process using a Process1 while keeping any remaining Process
def weave[O, B, F[_]](p: Process[F, O], p1: Process1[O, B])
(implicit M: Monad[F], C: Catchable[F]): F[(Seq[B], Process[F, O])] = {
// Nearly a direct copy of process1.feed, except it returns any unused inputs
def feed(i: Seq[O], p: Process1[O,B]): (Seq[O], Process1[O,B]) = {
@annotation.tailrec
def go(in: Seq[O], out: Vector[Seq[B]], cur: Process1[O,B]): (Seq[O], Process1[O,B]) =
if (in.nonEmpty) cur match {
case h@Halt(_) => (in, emitSeq(out.flatten, h))
case Emit(h, t) => go(in, out :+ h, t)