Skip to content

Instantly share code, notes, and snippets.

View Jacoby6000's full-sized avatar

Jacob Barber Jacoby6000

  • Plano, TX
View GitHub Profile
Miss Bell
Lars Hupel
John DeGoes
Tony Morris
Emily Pilmore
@Jacoby6000
Jacoby6000 / IO.scala
Last active January 19, 2018 17:16 — forked from jdegoes/IO.scala
A pedagogical implementation of the IO monad in Scala in 14 LOC
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
val attempt = IO(() => IO.tryIO(unsafePerformIO()) // lift IO[A] to IO[Either[Throwable,A]]
attempt.unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
@Jacoby6000
Jacoby6000 / readjsonfile.scala
Last active August 7, 2017 19:58 — forked from patientplatypus/readjsonfile.scala
im trying to get a simple read of some json object class in scala and running into trouble
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.functional.syntax._
import JsonFormats._
/**
* This controller creates an `Action` to handle HTTP requests to the
class IndexProcess private (config: Config) {
// e.g.
// index {
// entities {
// slide {
// products: {to: many, is: product}
// sites: {to: many, is: site}
// }
// site: {
val formattedPredictions: List[Option[String]] = predictions.map(_.classPredictions.headOption.map(_.prediction))
val formattedLabels: List[Option[String]] = data.map(_.label)
val (guesses, truths): (List[String], List[String]) = (
for {
(guess, truth) <- formattedPredictions zip formattedLabels
realGuess <- guess
realTruth <- truth
}yield(realGuess, realTruth)
).unzip
@Jacoby6000
Jacoby6000 / nope.scala
Last active January 5, 2017 23:50 — forked from zeryx/nope.scala
package algorithmia.TechSupport
import algorithmia.TechSupport.Classes.DataPoint
import argonaut.Argonaut._
import argonaut.CodecJson
import argonaut._
/**
* Created by james on 05/01/17.
*/
@Jacoby6000
Jacoby6000 / def.scala
Last active January 5, 2017 22:44 — forked from zeryx/def.scala
object Input {
implicit def inputCodec: CodecJson[Input] = {
def encoder(data: Input): Json =
data match {
case train: Train => Train.trainCodec.encode(train)
case predict: Predict => Predict.predictCodec.encode(predict)
}
def decoder(json: HCursor): DecodeResult[Input] =
package algorithmia.TechSupport
import algorithmia.TechSupport.Classes.DataPoint
import argonaut.Argonaut._
import argonaut.CodecJson
/**
* Created by james on 05/01/17.
*/
@Jacoby6000
Jacoby6000 / write.scala
Last active January 5, 2017 21:26 — forked from zeryx/write.scala
//converts any serializable class into json using shapeless
def write[A](input: A)(implicit encoder: EncodeJson[A]): Json = {
val json = encoder(input)
json
}
def apply(input: String): String = {
val output =
Utils.read[SealedTraitParent](input) match {
case Some(predict: Predict) =>
println(predict)
predict.process(client)
case Some(train: Training) =>
println(train)
train.process(client)
case None =>