Skip to content

Instantly share code, notes, and snippets.

View mattroberts297's full-sized avatar

Matt Roberts mattroberts297

View GitHub Profile
$ traceroute lodash.com
traceroute to lodash.com (83.137.145.21), 64 hops max, 52 byte packets
1 192.168.1.254 (192.168.1.254) 3.152 ms 2.516 ms 2.952 ms
2 217.32.147.4 (217.32.147.4) 10.234 ms 12.651 ms 10.333 ms
3 217.32.147.46 (217.32.147.46) 12.023 ms 11.620 ms 10.780 ms
4 213.120.156.194 (213.120.156.194) 14.348 ms 14.435 ms 13.077 ms
5 217.41.168.249 (217.41.168.249) 12.791 ms 12.756 ms 11.999 ms
6 217.41.168.109 (217.41.168.109) 12.342 ms 12.376 ms 12.919 ms
7 109.159.249.248 (109.159.249.248) 12.970 ms
acc2-te0-0-0-20.l-far.21cn-ipp.bt.net (109.159.249.220) 12.824 ms
@mattroberts297
mattroberts297 / SprayRoutingPitfall.scala
Created August 11, 2014 10:41
Spray Routing Pitfall
def route = path("foo") {
get {
complete {
println("In foo") // Run on request, not run at start up :-).
BodylessHttpResponse(OK)
}
}
} ~ path("bar") {
get {
println("In bar") // Run at start up, not run on request :-(.
@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._
@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 / WarmUpScalaz.scala
Created September 14, 2015 14:25
Warm up scalaz
import scalaz._
import Scalaz._
trait WarmUpScalaz {
private val warmMeUp = 1.success
}
@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 / 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 / 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 / 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 / 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))))