Tuesday, April 1, 2014

Reactive Mongo pattern: Serialize Joda DateTime

I really like ReactiveMongo. That said there are not enough code examples out there. So I'm gong to try to help. Here is a simple snippet which will allow you to serialize Joda DateTime instances to MongoDB.

Grunt recipe: Deploy to remote server with SSH

I finally moved my AngularJS apps over to Grunt mostly by following a great blog post here:

Kickstart Your AngularJS Development with Yeoman, Grunt and Bower

I have several sites that I host on a DigitalOcean micro instance and I wanted to make it as easy as possible to deploy new code. First I just tried using GitHub to pull the code on my server and build it there. Unfortunately I ran into problems because my server didn't have enough memory. That's not really a great solution anyway. Instead I added a Grunt task which uses SSH to copy my dist folder to the new server and take care of the deploy steps. Here is what it looks like:

This makes use of the Grunt Shell plugin. I create a tarball of the dist directory to save space. I also modified my Grunt tasks to only package files from the bower-components directory that I needed which made the dist much smaller. I would recommend setting up public key authentication to the servers in question.

Wednesday, January 8, 2014

Scala/Spray ReactiveMongo Recipe: Spray Path Matcher for BSONObjectID

This is a pretty simple one. Spray is implemented such that it is very easy to extend with nothing more than Scala code. In this case I wanted to provide an endpoint that could take a Mongo ObjectID as a path parameter. I had some other endpoint that were taking string patterns as the path parameter so I couldn't just use a String matcher without having special logic to tell which specific endpoint the user really wanted to hit. So I created a new Spray PathMatcher which will try to parse the input as an ObjectID and create a rejection if it hits a parse error. This way Spray can continue looking for another endpoint that might be a better match for this particular request.