background preloader


Facebook Twitter

The Scalawags - Monthly podcasts about Scala language. Scala Puzzlers. OSI: Office of Secret Intelligence. Hi all, back again with the second part of the play scala+slick+postgres adventure.

OSI: Office of Secret Intelligence

In part 1, I touched on some of the hurdles I needed to overcome in order to get things up and running. In this article, I'd like to show you how to set up a quick and snappy testing environment. For starters, we will want a separate test database for postgres. For local tests, just manually create the database and user, and grant that user privileges to create tables, etc. on that database: Yes, I know, you don't need 3 psql calls to do this but it works and I'm extremely lazy.

Now, let's start looking at the bigger picture. Travis CI makes setting up CI testing with all sorts of things really easy. Very simply, we tell Travis we're using scala, java 8, specifying a shell script which will kick off our tests (source shown below), and that we want to use postgres and have it run the commands in before_script prior to running our tests.

The one thing here that needs explaining is the flywayLocations key. Roundup: Scala for Java Refugees. 13 Feb 2008 To be honest, I’m somewhat kicking myself for writing this post.

Roundup: Scala for Java Refugees

As I’ve said many times: roundup posts are for people who are too lazy to write real content. I can’t tell you how many blogs I’ve come across which have a roundup-to-post ratio of easily 3:1. You know it’s a bad sign when sites start having roundups of their roundups… Meta-roundups aside, I decided (after much deliberation) that a single post linking to all six parts of the series would be useful to one or two people.

Of course it’s always possible that you subscribe to my way of looking at things. ScalaTest. Establishing geek cred since 1305712800. Static typing - What is the purpose of type ascription in Scala. Coursera Scala Cheatsheet. Scala.Option Cheat Sheet. Λ Tony's blog λ The weblog of Tony Morris Many people who are coming in to Scala first encounter the Option type, which may be thought of (among other things) as a type-safe null.

scala.Option Cheat Sheet

They also encounter pattern matching as both a new and (relatively) powerful concept, but also one that is easy to understand. This leads to quite a lot of use of pattern matching and often excessively so in what I have observed. Particularly with a type as trivial as Option, it is almost always possible to do away with pattern matching by using a higher-order function. Def option[A, X](o: Option[A])(none: => X, some: => A => X): X = ... Then, all functions can be written in terms of this one and needn’t pattern match at all. Real-World Scala: Dependency Injection (DI) ← Posted: 2008-10-06 In this second post in the Real-World Scala series I am going to discuss how to implement/achieve Depenency Injection (DI) in Scala.

Real-World Scala: Dependency Injection (DI) ←

Scala is a very rich and deep language that gives you several ways of doing DI solely based on language constructs, but nothing prevents you from using existing Java DI frameworks, if that is preferred. Using the Cake Pattern The current strategy we are using is based on the so-called Cake Pattern. This pattern is first explained in Martin Oderskys’ paper Scalable Component Abstractions (which is an excellent paper that is highly recommended) as the way he and his team structured the Scala compiler. Note: I will try to explain things in steps which I refactor towards the final version (this is only to help with the understanding), so please wait with yelling: “This sucks!” First, let’s create a UserRepository (DAO) implementation. Now let’s create a user service (also a dummy one, merely redirecting to our repository).

Ok. Ok. Well, no. S-99: Ninety-Nine Scala Problems. These are an adaptation of the Ninety-Nine Prolog Problems written by Werner Hett at the Berne University of Applied Sciences in Berne, Switzerland.

S-99: Ninety-Nine Scala Problems

I (Phil Gold) have altered them to be more amenable to programming in Scala. Feedback is appreciated, particularly on anything marked TODO. The problems have different levels of difficulty. Those marked with a single asterisk (*) are easy. If you have successfully solved the preceeding problems you should be able to solve them within a few (say 15) minutes. Your goal should be to find the most elegant solution of the given problems. Solutions are available by clicking on the link at the beginning of the problem description. [I don't have example solutions to all of the problems yet. Working with lists In Scala, lists are objects of type List[A], where A can be any type. The solutions to the problems in this section will be in objects named after the problems (P01, P02, etc.).

In many cases, there's more than one reasonable approach. Roundup: Scala for Java Refugees. Effective Scala. Table of Contents Other languages 日本語Русский简体中文 Introduction Scala is one of the main application programming languages used at Twitter.

Effective Scala

Much of our infrastructure is written in Scala and we have several large libraries supporting our use. Scala provides many tools that enable succinct expression. Above all, program in Scala. Scala Documentation. Typesafehub/sbteclipse. » Quick starting Scalatra or In which I discover Scalatra and sbt Everything's Beta. Over the weekend, I was researching various frameworks for implementing a REST API.

» Quick starting Scalatra or In which I discover Scalatra and sbt Everything's Beta

Although I had already started the implementation using Tornado, I wanted to see what else was out there. And am I glad I looked. I discovered Scalatra which seems to be exactly what I was looking for; a lightweight, sinatra-esque way to map URLs to actions that easily lends itself to testing. I especially like the uber-readable way the tests are written. Who wouldn’t want to write tests like this? // taken from MyScalatraServletTests extends FunSuite with ShouldMatchers with ScalatraTests { // `MyScalatraServlet` is your app which extends ScalatraServlet route(classOf[MyScalatraServlet], "/*") test("simple get") { get("/path/to/something") { status should equal (200) body should include ("hi!

") I cloned the repo, ran the examples and decided my search had ended. However, while running the example was easy enough, I wasn’t sure of how to get started with an actual app. Good, now we are ready to start. How to compile and run scala code quickly in vim. Sbt — sbt Documentation. Programming Scala.