This documentation provides the commands, the branches and the references for the course. The commands are further organized as needed in each video clip.
If you feel something is missing, please make a change, and open a pull request to contribute!
Happy Learning!
Open-Sourced Libraries on Bintray
Live API Deployed on Heroku
so that you can time-travel the changes
m4_0_initial_commit
m4_1_first_calculator
m5_1_currency_api
m5_2_networth_multi_currency
m6_1_packaging
m6_2_bintray_oss
m6_3_deploy_api
java -version
brew --version
brew install sbt
sbt sbtVersion
Ubuntu and other Debian-based distributions
Red Hat Enterprise Linux and other RPM-based distributions
Gentoo
mkdir sbt101
cd sbt101
touch build.sbt
ll
sbt
scalaVersion
help
help compile
help clean
help test
cd sbt101
mkdir -p src/main/directory
// vi src/main/scala/HelloWorld.scala
object HelloWorld extends App {
println("Hello sbt!")
}
compile
run
// vi src/main/scala/Echo.scala
object Echo extends App {
println(s"You said: ${if (args.isEmpty) "nothing" else args.mkString(" ")}")
}
run A B C
clean
run
;clean ;run "aha! now I know"
!
clean
!!
help console
console
Echo.main(Array("I run from scala console as well"))
:q
exit
sbt clean
sbt clean compile
sbt "run A B C"
sourceDirectories
baseDirectory
scalaSource
target
source
// vi build.sbt
name := "sbt201"
name
help reload
reload
inspect name
reload
// vi build.sbt, change name
name := "sbt201"
reload
inspect package
inspect clean
inspect run
settings
settings -V
tasks
tasks -V
// vi build.sbt
lazy val emotion = settingKey[String]("How are you feeling")
emotion := "Fantastic!"
reload
help emotion
inspect emotion
emotion
// vi build.sbt
val randomInt = taskKey[Int]("Give me random number")
randomInt := scala.util.Random.nextInt
reload
help randomInt
randomInt
show randomInt
// vi build.sbt
val emotion = settingKey[String]("How are you feeling")
emotion := "Fantastic!"
val status = settingKey[String]("What is your current status?")
status := {
val e = emotion.value
s"Grateful and $e"
}
reload
status
// vi build.sbt
val emotion = settingKey[String]("How are you feeling")
emotion := "Fantastic!"
val randomInt = taskKey[Int]("Give me random number")
randomInt := {
println(emotion.value)
scala.util.Random.nextInt
}
reload
show randomInt
// vi build.sbt
val randomInt = taskKey[Int]("Give me random number")
randomInt := {
scala.util.Random.nextInt
}
val status = settingKey[String]("What is your current status?")
status := {
val r = randomInt.value
s"Grateful and $r"
}
reload
name
;reload ;compile
projects
calculators/compile
calculators/clean
project calculators
;clean ;compile
projects
reload
projects
;clean ;compile
;reload
projects
;clean ;compile
;clean ;run
;clean ;calculators/run 100 20
test
calculators/run
calculators/Test/run
compile
calculators/runMain CompoundInterest 5000 5 10
unmanagedBase
api/console
val r = requests.get("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")
r.statusCode
r.headers
r.headers("content-type")
import scala.xml._ // (that's why we needed scala-xml)
r.text
val xmlResponse = XML.loadString(r.text)
val currencyCodes: Seq[String] = (xmlResponse \\ "@currency").map(node => node.text)
// Explain how to fetch attributes in xml in scala, refer to medium article
val euroToCurrencyMultipliers: Seq[Double] = (xmlResponse \\ "@rate").map(node => node.text.toDouble)
val currencyCodeMultipliers = (currencyCodes zip euroToCurrencyMultipliers).toMap
European Central Bank Currency API
Working with XML in Scala
test
Test/parallelExecution
~test
calculators/runMain NetWorthMultiCurrency "100000 EUR,9000 USD" "59100 EUR,12200 USD"
;clean ;stage
ls calculators/target/scala-2.12/
ls api/target/scala-2.12/
calculators/target/universal/stage/bin/net-worth 100 20
calculators/target/universal/stage/bin/compound-interest 5000 5 10
api/target/universal/stage/bin/api
docker -v
docker:publishLocal
docker images
docker run -it calculators:0.1.0-SNAPSHOT 100 20
sbt-native-packager
Docker Desktop
bintrayChangeCredentials
;clean ;publish
ls -ltr ~/.ivy2/cache/calculators/calculators_2.12/jars
Bintray: Open-source your project
;reload ;api/runMain WebServer
curl -v http://localhost:8080/rates