This file contains hidden or 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 mass: Mass[Double] = 4.0 kg | |
val length: Length[Int] = 5 m | |
val time: Time[Int] = 1 s | |
val temperature: Temperature[BigDecimal] = BigDecimal("22.22") k | |
val speed = length / time | |
val area = length * length | |
val volume: Volume[Int] = (23 m) * (1 m) * (1 m) | |
val accel = (10.0 m) / ((1.0 s) * (1.0 s)) |
This file contains hidden or 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 scala.swing._ | |
import java.awt.Color | |
import javax.swing.ImageIcon | |
import java.lang.Thread | |
object Main extends SimpleSwingApplication { | |
def top = new MainFrame { | |
title = "Foo" | |
minimumSize = new Dimension(800, 640) |
This file contains hidden or 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 stop() { | |
if (loopThread != null) { | |
loopThread.stop() | |
loopThread = null | |
} | |
if (loadThread != null) { | |
loadThread.stop() | |
loadThread = null | |
} |
This file contains hidden or 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 oxnrtr.chat | |
import collection.mutable.{ArrayBuffer, HashSet, Buffer} | |
import akka.actor.{ActorRef, Actor} | |
import akka.event.EventHandler | |
sealed trait Event | |
/**Join tells the peer that there is a new peer and requests a list of known peers and messages. */ | |
case class Join(user: String, ipAddress: String) extends Event |
This file contains hidden or 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 oxnrtr.chat | |
import collection.mutable.{ArrayBuffer, HashSet} | |
import akka.actor.Actor | |
sealed trait Event | |
/**Join tells the peer that there is a new peer and requests a list of known peers and messages. */ | |
case class Join(user: String, ipAddress: String) extends Event |
This file contains hidden or 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 myActor = Actor.actorOf(new ChatPeer(localName, localIp)).start() | |
var abort = false | |
while (!abort) { | |
val input = Console.readLine("Send message (or type `:log` for the log): ") | |
if (input.trim() == ":log") | |
myActor ! Message(localName, System.currentTimeMillis(), input) | |
else | |
(myActor ? GetChatLog).as[ArrayBuffer[Message]].foreach(println) | |
} |
This file contains hidden or 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
Enter name: soc2 | |
Enter IP adress: 127.0.0.1 | |
Enter port number: 2002 | |
Send message (or type `:log` for the log): Foo | |
Send message (or type `:log` for the log): :join soc 127.0.0.1 2000 | |
Actor[chat:service:00b6a1b0-fb96-11e0-8f8c-0019d2b208ca] | |
(05:37:20) soc2: Foo | |
Send message (or type `:log` for the log): Foo | |
Send message (or type `:log` for the log): [GENERIC] [21.10.11 05:37] [RemoteClientError(java.net.ConnectException: Connection refused,akka.remote.netty.NettyRemoteSupport@663257b8,/127.0.0.1:2000)] | |
[GENERIC] [21.10.11 05:37] [RemoteClientError(java.net.ConnectException: Connection refused,akka.remote.netty.NettyRemoteSupport@663257b8,/127.0.0.1:2000)] |
This file contains hidden or 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
object UnitsTest extends App { | |
import metascala.Units._ | |
val length1 = m(23) | |
val length2 = m(17) | |
val area: Area = length1 * length2 // Works, Quantity[_2, _0] | |
val time = s(42) | |
val foo: Foo = time * length1 // Works, Quantity[_1, _1] | |
This file contains hidden or 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 metascala.test | |
object UnitsTest extends App { | |
import metascala.Units._ | |
val length1 = m(23) | |
val length2 = m(17) | |
val area: Area = length1 * length2 // Works, Quantity[_2, _0] | |
val time = s(42) |
This file contains hidden or 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 metascala | |
object Units { | |
import Integers._ | |
import Addables._ | |
import Subtractables._ | |
trait Unit { | |
type M <: MInt | |
type S <: MInt |