cd ${HOME}
| package trees | |
| object Main extends App { | |
| trait Node | |
| case class InnerTreeNode ( left:Node, right:Node, value:Int ) extends Node | |
| case object StopNode extends Node | |
| def leaf(x: Int): Node = InnerTreeNode(StopNode, StopNode, x) |
| import sbt._ | |
| import sbt.Keys._ | |
| object MyPlugin extends AutoPlugin { | |
| override lazy val projectSettings: Seq[Setting[_]] = Seq( | |
| resourceDirectory in Compile := file("/tmp") | |
| ) | |
| } | |
| object MyBuild extends Build { |
| for (int i = 0; i < 10_000; i++) { | |
| Thread t = new Thread(() -> System.out.println("doing something")); | |
| t.start(); | |
| t.join(); | |
| } | |
| // Eventually throws java.lang.OutOfMemoryError: unable to create new native thread |
| extern crate iron; | |
| extern crate mysql; | |
| use iron::prelude::*; | |
| use iron::status; | |
| use iron::{Handler}; | |
| struct Router { | |
| routes: HashMap<String, Box<Handler>> | |
| } |
| package object mail { | |
| implicit def stringToSeq(single: String): Seq[String] = Seq(single) | |
| implicit def liftToOption[T](t: T): Option[T] = Some(t) | |
| sealed abstract class MailType | |
| case object Plain extends MailType | |
| case object Rich extends MailType | |
| case object MultiPart extends MailType |
A big reason people love Go is the concurrency primitives. Let's try them out with a coding challenge.
Launch 2 go-routines that send messages to each other over a channel. One go-routine will send "Ping" and the other will send "Pong." Each go-routine can only respond after they've received a message from the other go-routine. The exception is that the go-routine sending "Ping" can send an initial message
Another strong component of Go is the standard library. It is structured much like the Unix/Linux operating system. There are lots of small components that can be combined together for more complex tasks. There are also indespensible, modern primitives such as the ability to create a networking server.
Create a web-server that exposes a typical AppNexus "status" endpoint. The web-server will support
| #include <google/protobuf/arena.h> | |
| using namespace google::protobuf; | |
| void main() { | |
| Arena arena; | |
| auto msg = Arena::CreateMessage<MyProto>(&arena); | |
| setup_myproto(msg); | |
| push_to_queue(msg); | |
| } |
| #include <google/protobuf/arena.h> | |
| using namespace google::protobuf; | |
| void main() { | |
| Arena arena; | |
| auto msg = Arena::CreateMessage<MyProto>(&arena); | |
| setup_myproto(msg, 1); | |
| push_to_queue(msg); |