View StreamFixedLength.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
val route = path("download") { | |
get { | |
optionalHeaderValueByName("Range") { | |
case None => | |
// there must always be range | |
complete(StatusCodes.RequestedRangeNotSatisfiable) | |
case Some(range) => | |
val file = new File("movie.mp4") | |
val fileSize = file.length() | |
val rng = range.split("=")(1).split("-") |
View streamcorrect.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
val route = path("download") { | |
get { | |
optionalHeaderValueByName("Range") { | |
case None => | |
// there must always be range header | |
complete(StatusCodes.RequestedRangeNotSatisfiable) | |
case Some(range) => | |
val file = new File("movie.mp4") | |
val fileSize = file.length() |
View stream_no_skip.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
val route = get { | |
path("download") { | |
val file = new File("movie.mp4") | |
respondWithHeaders(RawHeader("Content-Disposition", s"""attachment; filename="movie.mp4"""")) { | |
complete(HttpEntity(ContentTypes.`application/octet-stream`, FileIO.fromPath(file.toPath))) | |
} | |
} | |
} |
View Marshaller.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
trait MarshallingSupport | |
extends SprayJsonSupport | |
with DefaultJsonProtocol with Runtime[Unit] { self => | |
//implicit marshallers for my return Type A | |
implicit val todoItemFormatter = jsonFormat2(TodoItem) | |
implicit val todoNameFormatter = jsonFormat1(TodoName) | |
sealed trait ErrorToHttpResponse[E] { | |
def toHttpResponse(value: E): HttpResponse |
View PostgresDBNoEffect.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
sealed trait DatabaseDriver { | |
// //A lot of database config we don't care about | |
// //Database object | |
lazy val db = new ConnectionPool(_, _) | |
} | |
trait PostgresDatabase extends Database with DatabaseDriver { | |
private def runQuery(query: String): IO[Throwable, QueryResult] = { | |
for { | |
result <- ZIO.fromFuture(_ => db.sendPreparedStatement(query)) |
View PostgresDbEffect.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
sealed trait DatabaseDriver { | |
//A lot of database config we don't care about | |
//Database object | |
private val pool = new ConnectionPool(_, _) | |
//create an effect from the pool | |
lazy val db: UIO[ConnectionPool[MySQLConnection]] = UIO.fromFunction(_ => pool) | |
} | |
trait PostgresDatabase extends Database with DatabaseDriver { self => | |
private def runQuery(query: String): ZIO[DatabaseDriver, Throwable, QueryResult] = { |
View build.sbt
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
lazy val fetchConfFile = taskKey[File]("fetch Config file") | |
fetchConfFile := { | |
//simulate fetching a remote file | |
sLog.value.info("fetching file ...... ") | |
Thread.sleep(1000) | |
new java.io.File("/tmp/application.conf").createNewFile() | |
val configFile : File = new java.io.File("/tmp/application.conf") | |
sLog.value.info("done fetching file .... ") | |
configFile |
View build.sbt
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
lazy val zip = taskKey[Unit]("zip files") //define the key | |
zip := { // assigning a value to the zip key of type Unit | |
val logger: Logger = sLog.value //get logger from SBT | |
//where to zip from | |
val dirFromZip: File = srcFile.value | |
//where to zip to | |
val dirToZip: File = baseDirectory.value / "build.sbt.zip" | |
logger.info(s"zipping files from ${dirFromZip.absolutePath}") |
View build.sbt
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
name := "phony" | |
version := "0.2" | |
scalaVersion := "2.12.6" | |
organization := "com.phony" | |
libraryDependencies += "com.googlecode.libphonenumber" % "libphonenumber" % "8.10.23" | |
scalacOptions := Seq( // commands passed to the scala compiler | |
"-feature", | |
"-unchecked", | |
"-deprecation", |
View build.sbt
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
name := "phony" | |
version := "0.2" | |
scalaVersion := "2.12.6" | |
organization := "com.phony" | |
libraryDependencies += "com.googlecode.libphonenumber" % "libphonenumber" % "8.10.23" |
NewerOlder