Miguel Angel Gordian
Software Engineer.
Miguel Angel Gordian
#!/usr/bin/env scala
try {
while(true) {
val line = readLine("Escribe una oracion")
.split('\n')
.map(_.trim.filter(_ > ' '))
.mkString
.toLowerCase
if (line == line.reverse)
println("Es un palindromo")
else
println("No es un palindromo")
}
}
name := "Palindromo"
version := "1.0"
scalaVersion := "2.11.8"
build.sbt
object Palindromo {
def main(args: Array[String]) = {
while(true) {
val line = readLine("Escribe una oracion")
.split('\n')
.map(_.trim.filter(_ > ' '))
.mkString
.toLowerCase
if (line == line.reverse)
println("Es un palindromo")
else
println("No es un palindromo")
}
}
}
palindromo.scala
Iluminación funcional
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
class HelloActor extends Actor {
def receive = {
case "hello" => println("hello back at you")
case _ => println("huh?")
}
}
object Main extends App {
val system = ActorSystem("HelloSystem")
val helloActor = system.actorOf(Props[HelloActor],
name = "helloactor")
helloActor ! "hello"
helloActor ! "buenos dias"
}
actores.scala
Fuente: http://alvinalexander.com/scala/simple-scala-akka-actor-examples-hello-world-actors
class MySimulation extends Simulation {
val conf = http.baseUrl("http://localhost")
val scn = scenario("Gatling")
.exec(http("index").get("/"))
.during(10 minutes) {
exec(
http("json").get("/json")
.check(jsonPath("$.id")
.saveAs("id"))
)
}
setUp(scn.inject(atOnceUsers(5)))
.protocols(conf)
}
load_testing.scala
60 PRINT "You are drifting towards the moon."
70 PRINT "You must decide how much fuel to burn."
80 PRINT "To accelerate enter a positive number"
90 PRINT "To decelerate a negative"
100 PRINT "Distance " % 'dist % "km, " % "Velocity " % 'v % "km/s, " % "Fuel " % 'fuel
110 INPUT 'burn
120 IF ABS('burn) <= 'fuel THEN 150
130 PRINT "You don't have that much fuel"
140 GOTO 100
150 LET ('v := 'v + 'burn * 10 / ('fuel + 'mass))
160 LET ('fuel := 'fuel - ABS('burn))
170 LET ('dist := 'dist - 'v)
180 IF 'dist > 0 THEN 100
190 PRINT "You have hit the surface"
200 IF 'v < 3 THEN 240
210 PRINT "Hit surface too fast (" % 'v % ")km/s"
220 PRINT "You Crashed!"
230 GOTO 250
240 PRINT "Well done"
250 END
RUN
luna_lander.scala
By Miguel Angel Gordian