Skip to content

Instantly share code, notes, and snippets.

@calippo
calippo / Http4sEndpoints.scala
Created January 14, 2020 09:17
tapiro http4s
object ControllerHttp4sEndpoints {
def routes(controller: Controller[F])(
implicit ...
): HttpRoutes[F] = {
val endpoints = ControllerEndpoints.create()
val getContainers =
endpoints.getSomething.toRoutes((controller.getSomething _).tupled)
val getContainerStatus = endpoints.doSomething.toRoutes(controller.doSomething)
)
NonEmptyList(
@calippo
calippo / endpoints.scala
Last active January 14, 2020 09:15
tapiro endpoints
object ControllerEndpoints {
def create(statusCodes: String => Int = _ => 422)(
implicit stringJsonCodec: JsonCodec[String],
listJsonCodec: JsonCodec[Result],
) = new DockerMonitorControllerFEndpoints {
override val getSomething
: Endpoint[String, GenericError, Result, Nothing] =
endpoint.get
.in("getContainers")
@calippo
calippo / Controllers.scala
Last active January 14, 2020 09:12
tapiro models
import scala.annotation.StaticAnnotation
class query extends StaticAnnotation
class command extends StaticAnnotation
import io.circe.generic.JsonCodec
@JsonCodec case class GenericError(
message: String = "",
code: Int = 500
)
@calippo
calippo / build.sbt
Last active January 14, 2020 09:10
tapiro build.sbt
lazy val dockerMonitor = project
.settings(libraryDependencies ++= dependencies)
.settings(
tapiro / tapiroRoutesPath := "relative path to the routes",
tapiro / tapiroModelsPath := "relative path to the models",
tapiro / tapiroOutputPath := "relative path for the generated models",
tapiro / tapiroEndpointsPackage := cats.data.NonEmptyList("dockerMonitor", Nil),
)
.enablePlugins(SbtTapiro)
.dependsOn(authContracts)
package intervals
import scala.language.implicitConversions
import cats.Monoid
import cats.syntax.foldable._
import cats.instances.list._
import scala.math.Ordering
object Main extends App {
import Interval._
@calippo
calippo / goemailgo.sh
Last active March 2, 2018 16:32
Send email from command line
echo “very spoofy” | mail -s “much boring” [email protected]
@calippo
calippo / midi.py
Last active November 7, 2017 22:04
python-midi example
import midi #pip install python-midi (https://github.com/vishnubob/python-midi)
pattern = midi.Pattern()
track = midi.Track()
pattern.append(track)
on = midi.NoteOnEvent(tick=0, velocity=100, pitch=60)
track.append(on)
off = midi.NoteOffEvent(tick=100, pitch=60)
track.append(off)
eot = midi.EndOfTrackEvent(tick=1)
@calippo
calippo / sbt_alias
Last active August 18, 2017 10:56
Alias sbt to log compilation errors
alias sbt='f() { sbt "$@" |tee -a ~/.sbtlogs; };f'
@calippo
calippo / CaseClassLink.scala
Last active August 29, 2017 11:10
Given a sealed trait A and a case class B, force the case class to have as parameters all and only the known subclasses of A (at compile time with shapeless)
@calippo
calippo / crane-jupyter-dev.yml
Last active April 22, 2017 10:06
Simple jupyter crane file bootstrap for dev
containers:
env:
image: davidshen84/scikit-learn
run:
publish:
- 8888:8888
interactive: true
tty: true
volume: ["./data:/data", "./notebook:/notebook"]