Wednesday, September 12, 2012

Screen Surprise

A few days back, I lost reference to a Spark(http://www.spark-project.org/) job because my ssh session to the remote machine got disconnected. My colleague was surprised that I wasn't using screen. I was surprised at his surprise because I had heard of screen exactly once before that day. I had no idea it was that popular. I decided to give it a try today.

To my surprise screen was already installed on the remote machine I tried it on, it must be really popular after all. Having used it for just about 30 minutes I can see why it is so useful. Sounds like a must have tool. There is enough information about it on the web so I will just provide a few commands here:

# screen
Creates a new screen window

#screen -ls
Lists available screen windows

#screen -r
Connect to a screen window

Once in screen window you can do Ctrl-A d to detach from the screen, it keeps running in the background.

The most important use case for me is that even if my ssh session drops accidentally the screen session keeps running on the machine and I can reconnect to it on my next login.

Sunday, September 2, 2012

Easy start with sbt

I'm loving scala and I can see myself creating a lot of sbt projects in the future. To avoid writing the boilerplate structure of sbt project everytime I start I created this simple bash function to do that for me:


function create_sbt_project() {
  project_folder=$1
  mkdir $project_folder
  pushd $project_folder
  git init
  echo -e "name := \"$1\"\n\nversion := \"1.0\"\n\nscalaVersion := \"2.9.1\"" > build.sbt
  mkdir -p src/main/resources
  mkdir -p src/main/scala
  mkdir -p src/main/java
  mkdir -p src/test/resources
  mkdir -p src/test/scala
  mkdir -p src/test/java
  echo -e "object Hi {\n  def main(args:Array[String]) = println(\"Hi!\")\n}" > src/main/scala/hw.scala
  echo target/ >> .gitignore
  git add .
  git commit -m "Initial Commit"
  sbt compile run clean
  popd
}


e.g.
$ create_sbt_project test

will create a folder with standard sbt project structure that compiles and runs.

Saturday, September 1, 2012

Syntastic Scala fix

Syntastic is an awesome vim plugin. I've been programming in scala recently and syntastic works with scala which is awesome, except one issue which has been annoying me. Since syntastic uses "scala" on the command line to find errors in the script it considers the package statement at the start of the script as an error. "scalac" is a better command to find the errors but when compiling a file in isolation it compains about imports from dependent libraries. A reasonable option seems to be stop scalac after the parsing step.

Here's the patch:

diff --git a/syntax_checkers/scala.vim b/syntax_checkers/scala.vim
index f6f05af..941054d 100644
--- a/syntax_checkers/scala.vim
+++ b/syntax_checkers/scala.vim
@@ -24,7 +24,7 @@ if !exists("g:syntastic_scala_options")
 endif

 function! SyntaxCheckers_scala_GetLocList()
-    let makeprg = 'scala '. g:syntastic_scala_options .' '.  shellescape(expand('%')) . ' /dev/null'
+    let makeprg = 'scalac -Ystop-after:parser '. g:syntastic_scala_options .' '.  shellescape(expand('%'))

     let errorformat = '%f\:%l: %trror: %m'


Basically just set makeprg to 'scalac -Ystop-after:parser '. g:syntastic_scala_options .' '.  shellescape(expand('%'))