Posts
Writing a Daytime Server with Akka Streams
Inspired by this article which shows how to implement a daytime server with swift NIO I thought I’d show how do the same on top of Akka in Scala.
Prerequisites To follow this little guide you are expected to have a JDK installed and sbt the Scala build tool. If you do not, start with getting those installed: https://www.scala-sbt.org/1.x/docs/Setup.html
Creating a project In a suitable directory, create a new project from the sbt akka-quickstart template: $ sbt new akka/akka-quickstart-scala.
Posts
Chat With Akka HTTP Websockets
This is an update of an older article using the new MergeHub and BroadcastHub that was introduced in Akka Streams 2.4.10 instead of actors for the dynamic registration of clients. If you are after modelling the chat room and users with actors the old article is still relevant!
Something that often comes up in the various Akka community channels is people who want to create a HTTP chat application but get stuck, they often get stuck on the same thing, so let us go through how one could build such a thing.
Posts
Actor per Request With Akka Http
Akka HTTP is the continuation of Spray, which used to be the web server implemented on top of Akka. A common pattern from Spray that devs want to implement with Akka HTTP is “actor per request” where each request is sent to an actor whose life cycle is bound to the request, so it is started, gets the request, does some processing and produces a complete or failed result back to the HTTP client.
Posts
Chat With Akka HTTP Websockets
Note since this was written Akka Streams has gained two dynamic stages that makes this possible without using actors which simplifies the wiring a lot if you are not after modelling the chat with actors.
See new article for more details.
Something that often comes up in the various Akka community channels is people who want to create a chat application but get stuck, they often get stuck on the same thing, so let us go through how one could build such a thing.
Posts
Futures Plus Supervision in Akka
Reading a blog entry by Paul Cleary made me feel the simple and nice solution was missing when reaching the end of the blog entry, so here you go, what I would have ended it with.
Ideally what we’d want is something pretty close to the pipe pattern built into Akka, but we want to divide errors to the local actor and only send successfully completed future values to the recipient.
Posts
Review - Scala for Machine Learning
TL;DR I think this book has got a lot of flaws but is definitely worth owning if you are interested in Machine Learning. It does require a pretty good grasp of both Scala and maths to be useful though.
First impression I was excited when got a copy of this book for review since I had recently attended a few conference talks on Machine Learning that were all either just shallow enough to spark interest or so deep into the maths that they were incomprehensible.
Posts
Scala Collection API:s vs Java 8 Streams
Inspired by this article http://blog.informatech.cr/2013/03/24/java-streams-preview-vs-net-linq/ written by Edwin Dalorzo I wanted to do the same thing but with the Scala collection API to get a feel for how the upcoming Java 8 Stream API compares. I have selected a subset of the streams examples from Edwins blog entry, just copying his Java solution to each, so props to him for them!
Challenge 1: Filtering Say we have a List of names and we want to find each name that contains the substring “am”:
Posts
Formatted Localized Dates in Playframework 2
A question I see popup every now and then on the play mailing list is how to format dates in play framework templates. A lot of people seem to find it hard to understand why their dates are not formatted according to the locale they expect, sometimes they expect their native language to be automagically selected, some times the browser locale.
So, to ease the confusion, a small guide to formatting dates in play framework.
Posts
Unparsing With ANORM in Play Framework 2
I recently wrote about how to approach ANORM when parsing SQL results into domain model objects, in most cases you also want to write data to your relational database. The following is one way to do the reversed mapping in a general way and avoiding repeating yourself over and over again.
A basic ANORM inserts looks like this:
SQL("INSERT INTO my_table (col1, col2) VALUES ({id1}, {id2})") .on("id1" -> value1, "id2" -> value2) .
Posts
Parsing With ANORM in Play Framework 2
Being used to JPA/Hibernate it took a while to figure out how powerful and easy ANORM actually is. So as a help for other people trying to wrap their head around ANORM, here are some hints:
Parse one db table (or query result) with many columns into smaller parts: One common problem is creating a more rich domain model than the database schema, this is how you could achieve that by combining parsers: