Skip to content

Instantly share code, notes, and snippets.

View mattroberts297's full-sized avatar

Matt Roberts mattroberts297

View GitHub Profile
@mattroberts297
mattroberts297 / akka-http-docs.sh
Created August 16, 2017 21:29
Generate akka http docs
git clone git clone https://github.com/akka/akka-http.git
cd akka-http
sbt ";project docs; paradox"
open docs/target/paradox/site/main/index.html
@mattroberts297
mattroberts297 / akka-docs.sh
Created August 16, 2017 21:19
Generate akka docs for offline use
git clone [email protected]:akka/akka.git
cd akka
sbt ";project akka-docs; paradox"
open akka-docs/target/paradox/site/main/index.html
@mattroberts297
mattroberts297 / EitherOptionT.scala
Last active November 16, 2018 19:48
Monad transformers and stuff
package data
import cats.Functor
import cats.Monad
import cats.syntax.either._
final case class EitherOptionT[F[_], A, B](value: F[Either[A, Option[B]]]) {
def map[C](f: B => C)(implicit F: Functor[F]): EitherOptionT[F, A, C] =
EitherOptionT(F.map(value)(e => e.map(o => o.map(f))))
@mattroberts297
mattroberts297 / Monad.puml
Created August 3, 2017 13:03
Cats class diagrams
@startuml
skinparam monochrome true
skinparam classFontSize 16
skinparam classFontStyle "Regular"
skinparam classFontName "Gill Sans"
skinparam classAttributeFontSize 14
skinparam classAttributeFontStyle "Regular"
skinparam classAttributeFontName "Gill Sans"
@mattroberts297
mattroberts297 / CirceSupport.scala
Created August 2, 2017 19:51
Akka HTTP Circe Custom Marshaller and Unmarshaller
import io.circe._
import io.circe.parser._
import io.circe.syntax._
import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model.{ContentTypeRange, HttpEntity}
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import scala.concurrent.Future
@mattroberts297
mattroberts297 / index.html
Created April 14, 2017 20:35
Pixi tutorial step 1
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<script src="node_modules/pixi.js/dist/pixi.min.js"></script>
<script src="index.js"></script>
</body>
@mattroberts297
mattroberts297 / ncloop.sh
Last active September 27, 2022 14:21
netcat in a loop
#!/bin/bash
for i in `seq $1 $2`; do
echo Message $i | nc 127.0.0.1 9997
sleep 1
done
@mattroberts297
mattroberts297 / WarmUpScalaz.scala
Created September 14, 2015 14:25
Warm up scalaz
import scalaz._
import Scalaz._
trait WarmUpScalaz {
private val warmMeUp = 1.success
}
@mattroberts297
mattroberts297 / RemoveTieFighter.scala
Last active September 14, 2015 13:30
Remove the Tie Fighter / Admiral Ackbar operator
// With Tie Fighter
(validNumberNel(keyJsOpt, _.toLongExact) |@| validNumberNel(valueJsOpt, _.toIntExact)) {
case (key, value) => Measurement(name, key, value)
}
// Without Tie Fighter
type V[T] = ValidationNel[String, T]
Apply[V].apply2[Long, Int, Measurement](validNumberNel(keyJsOpt, _.toLongExact), validNumberNel(valueJsOpt, _.toIntExact)) {
case (key, value) => Measurement(name, key, value)
}
@mattroberts297
mattroberts297 / Main.scala
Created June 23, 2015 15:54
akka-http 1.0-RC3
import java.io.File
import java.util.UUID
import akka.actor.ActorSystem
import akka.http.scaladsl.model.headers.Location
import akka.http.scaladsl.model.{HttpEntity, StatusCodes, HttpResponse}
import akka.stream.{FlowMaterializer, ActorFlowMaterializer}
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.io._