Showing posts with label Scala. Show all posts
Showing posts with label Scala. Show all posts

Scala and Fibonacci

Posted on Saturday, June 14, 2014


After doing a few neat one liners in Scala I wondered what was a slick way to calculate the Fibonacci numbers using Scala.


The simplest solution was made by Luigi Plinge. And here it is




val fibs: Stream[Int] = 0 #:: fibs.scanLeft(1)(_ + _)



Scala Create All Paths

Posted on Thursday, June 12, 2014


I was recently talking to a colleague of mine who had been presented a problem from a friend of his.   In Scala take a files path as a string and return all sub paths of that string.

… In other words

Given a path as a String like this


val str:String = "/foo/bar/test/me"


Scala Convert List of Strings to Ints, List[String] => List[Int]

Posted on Monday, May 12, 2014


I am still fairly new to Scala so take what I write in this article with a grain of salt.


The more I learn Scala to more I like it and here is an example of why…

The following Scala Code will read in a file (whos name is the first command line argument) and read in every line as a String Array, convert it to a List[String] then convert that to a List[Int]  (this assumes the file has a valid integer on each line.  Then it prints out the Int list adding +1 to each number as it prints it out.


 
import scala.io.Source

object ListStringToInt{

  def main(args: Array[String]) {
    val sList = Source.fromFile(args(0)).
      getLines.toList.map((s: String) => s.toInt)

    sList.foreach((x: Int) => println(x + 1))
  }
}


Scala and sbt

Posted on Monday, February 3, 2014


This guide goes over installing and using the sbt plugin.
This guide was written using an Ubuntu 12.04 server.

Jenkins and sbt

Posted on Wednesday, January 29, 2014


This guide will go over installing the sbt plugin for Jenkins.  This guide assumes you Jenkins already installed and running and has the git plugin. 

If you do not have Jenkins installed I wrote up a guide to show you how at http://www.whiteboardcoder.com/2014/01/install-jenkins-ubuntu.html

If you do not have the git plugin for Jenkins installed I wrote up a guide on that too at http://www.whiteboardcoder.com/2014/01/git-with-jenkins.html


(1 of 4) Amazon ELB Multi-domain SSL forwarding to NGINX and Play Servers

Posted on Wednesday, April 10, 2013



(1 of 4  Install Scala and Play on Ubuntu 12.10)

This guide goes over setting up an ELB with a multi-domain SSL certificate.  The servers attached to the ELB will run multiple Play servers on different ports with an nginx server running in front of them to handle routing based on domain/subdomain names.

I know that is quite a mouthful but here is what I am trying to accomplish….

I want to run more than one Play Server on an ec2 instance.  Each Play Server will run on its own port.   I want to have a domain name to route to a specific Play server.  Ex.  www.example.com routes to the Play server running on port 9000 and  www2.example.com routes to the Play server running on port 8000.   In addition I want all the communication to be secure using ssl certificates.

For an individual server you could simply put a nginx server in front of the Play servers and have the nginx handle routing based on domain name.  But, in this case I want to add an AWS ELB (Elastic Load Balancer) in front of several EC2 machines.

Here is what I have found out thus far.   The ELB can handle the ssl certificate, but it can only have one certificate per ELB.  This forces you to use a multi-domain SSL certificate.   Also the ELB cannot port forward based on domain name so you still need an nginx server in front of the Play servers.




I want something like this.  The ELB handles the certificate and the nginx server handles the domain name routing.


Play with Apache or nginx forwarding on Ubuntu 12.10

Posted on Thursday, March 21, 2013


I am still playing around with scala play so I may be mistaken in this idea… so take that into mind as I describe what I am doing…

I have a need to run multiple scala applications on the same server for different domain names.   I think I can do this if I have apache or nginx as the front end HTTP server sending the correct address to the correct scala play app.  I also need to run all of this on an ubuntu  12.10 server.

At any rate here is what I did to accomplish that.


Scala Hello World

Posted on Monday, March 4, 2013



This is just a real quick Scala HelloWorld program.  I am going to install Scala on my Windows 7 box and on an ubuntu server I have handy.


Install Scala on Win 7


In this section I will go over installing Scala in a Windows 7 environment.

First we need to download  Scala for windows

Go to http://www.scala-lang.org/downloads and download scala.