This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def doWork[A: Numeric, B: Numeric](values: Seq[Option[A]], op: String): Option[B] = { | |
import spire.implicits._ | |
val v = values.flatten | |
if (v.isEmpty) { | |
None | |
} else { | |
op match { | |
case "sum" => Some(v.qsum) // returns A | |
case "avg" | "avg" => Some(v.qsum / v.length) // returns Double | |
case "max" => Some(v.qmin) // A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val x:Double = Long.MaxValue // x: Double = 9.223372036854776E18 (9223372036854775807) | |
scala> x == Long.MaxValue // Boolean = true | |
scala> x.longValue == Long.MaxValue // Boolean = true | |
scala> val y = 1234567890123456789L // y: Long = 1234567890123456789 // less than Long.MaxValue | |
scala> y < x // Boolean = true | |
scala> val z:Double = y // z: Double = 1.23456789012345677E18 | |
scala> z == y // Boolean = true | |
scala> z.longValue == y // Boolean = false // why ? MaxValue fits in the Double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def safeSum[A: Numeric](as: Seq[A]):Option[A] = | |
if (as.isEmpty) None else Some(as.qsum) | |
def safeDiv[A: Numeric](a:Option[A], b:Option[A]):Option[Double] = (a,b) match { | |
case (None,_) | (_,Some(0)) | (_,None) => None | |
case (Some(x),Some(y)) => Some((x / y).toDouble()) | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.soqqo.luap.web.marshalling | |
import org.scalatest.FlatSpec | |
import org.scalatest.matchers.ShouldMatchers | |
import io.straight.fw.spray.marshalling.JacksonUnmarshaller | |
import com.soqqo.luap.messages.AddNewAccountTenantRegistration | |
import spray.httpx.unmarshalling._ | |
import spray.util._ | |
import spray.http._ | |
import spray.http.MediaTypes.`application/json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.soqqo.luap.messages | |
import com.soqqo.luap.messages.ContextMetaData | |
import com.soqqo.luap.messages.NoContextMetaData | |
import com.soqqo.luap.messages.RegisterNewPerson | |
import io.straight.fw.model.Uuid | |
import scala.reflect.api.JavaUniverse | |
import scala.reflect.api | |
import io.straight.fw.jackson.JacksonBindingSupport._ | |
import scala.Some |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.DateTime | |
import com.soqqo.luap.model.common.Address | |
import io.straight.fw.model.Uuid | |
import java.util.Date | |
import akka.actor.ActorRef | |
/* | |
* file: CampusMessages.scala | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author rbuckland | |
*/ | |
trait H2DatabaseGenerator extends CommonHttpService { | |
val generateH2DbRoute = pathPrefix("h2generator") { | |
// headerValueByName("Upload-File-Name") { filename => | |
// headerValueByName("DatabaseName") { dbname => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is some configuration I have used to run a a Scala base SBT webapp on Heroku. | |
Heroku suggest using startscript. But this doesn;t work on Mac OSX *readline, it also uses an embedded jetty verison, and it uses the jetty distribution. | |
Instead, Heroku suggest using jetty-runner with Java Maven projects (and I liked that a lot) so I am replicating that setup here. | |
In short: | |
1. Ensure you have the xsbt-web-plugin |
NewerOlder