Thursday, 28 April 2011

Add JRebel to SBT

This allows for continuous reloading when doing Lift development

set SCRIPT_DIR=%~dp0
java -Dhttp.proxyHost=<proxy-server> -Dhttp.proxyPort=<proxy-port> -Xmx512M -Drebel.license=<path-to-jrebel>/javarebel.lic -noverify -javaagent:<path-to-jrebel>/jrebel.jar -jar "%SCRIPT_DIR%sbt-launch-0.7.5.jar" %*
  • From sbt console run 
    > ~prepare-webapp

Setup Lift (Scala web framework)

  • Create new folder 'LiftProject'
  • Run sbt command from that folder, choose 'y' to create new project (Name: LiftProject, Organization: test)
  • Configure Lifty ( Lift SBT processor - you only need to do it once
    • From sbt prompt run the following (including * character)
        > *lifty is org.lifty lifty 1.6.1 
        > update
  • Create new Lift project (when asked you can specify version 2.3 instead of 2.3-RC3)
      > lifty create project-blank
  • Create idea project files 
    > idea
  • Refresh everything 
    > reload
    > update
    > compile
  • Run Jetty webserver
    > ~jetty-run
  • Open http://localhost:8080 and you should see your lift webpage

More info about Lift

Lift Book
code samples:

How to configure git http proxy

git config --global http.proxy {servername}:{portnumber}

Thursday, 21 April 2011

Setup Scala with SBT in IntelliJ IDEA

Download Dependencies


  • Setup SBT according to this page (Launching Sbt section)
  • Add Scala/SBT plugins to IntelliJ IDEA
    • Go to File/Settings/Plugins, choose Available tab, right click on Scala plugin and click on 'Download and Install'. Do the same for SBT plugin.
    • Restart IntelliJ IDEA
    • Go to File/Settings/SBT and set location of your SBT jar file and if you're on windows behind firewall add proxy info to vm params (-Dhttp.proxyHost=<proxy_server> -Dhttp.proxyPort=<proxy_port>)

Create Project

  • Create new Folder ScalaProject
  • Run sbt command from that folder, choose 'y' to create new project (Name: ScalaProject, Organization: test) 
  • Configure sbt-idea plugin ( - you only need to do it once
    • From sbt prompt run the following (including * character)
        > *sbtIdeaRepo at
        > *idea is com.github.mpeltonen sbt-idea-processor 0.4.0
        > update
  • Create idea project files
      > idea
  • Open the project in IntelliJ IDEA
  • Configure scala plugin file for sbt-idea
    • Create directory ScalaProject/project/plugins
    • Create new file Plugins.scala in ScalaProject/project/plugins folder 
import sbt._ 
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val sbtIdeaRepo = "sbt-idea-repo" at ""
  val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.2.0"
  • Configure sbt project definition file
    • Create directory ScalaProject/project/build
    • Create scala class file ScalaProject in ScalaProject/project/build folder
import sbt._ 
class ScalaProject(info: ProjectInfo) extends DefaultProject(info) with IdeaProject {
  val scalatest = "org.scalatest" % "scalatest" % "1.3"
  • Refresh project files   
    • Launch SBT Console (bottom of the screen) and press Run (green arrow) 
    • From SBT prompt run the following
      > update
      > clean
      > compile
      > idea   
    • Reload the project

Hello World example

  • Create new scala class HelloWorld in src/main/scala
object HelloWorld {
  def main(args: Array[String]){
  def hello:String = {
    return "Hello World!";
  • Create new scala test class HelloWorldSpec in src/test/scala
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
class HelloWorldSpec extends FlatSpec with ShouldMatchers {
  "Hellow World" should "show Hello World" in {
    HelloWorld.hello should equal("Hello World!")

Testing Hello World example

  • Launch SBT Console to run the examples
  • From SBT prompt run the following
    > run (searches for classes with main(args) method and executes them)
    > test (searches for test classes and execute them)
    > ~test (runs tests continuously as soon as it detects changes), press ENTER to exit

Enjoy Scala!

This seems like a good tutorial for beginners

Friday, 1 April 2011

C# SQLite Example

Create new SQLite database using wxSQLite or command line c:\temp\contacts.db

In Your C# Project

  • Add References to System.Data.SQLite
  • Add sqlite3.dll (as link) to your project and set Copy to Output Directory property to Copy if newer

C# Test to create table and read some data.

public class TestSqlLite
    #region sql
    private string createSql = @"
FirstName TEXT,
LastName TEXT
SELECT 'Michael','Jordan'
UNION SELECT 'Scottie','Pippen'
    private string selectSql = @"SELECT * FROM Contacts";
    public void Test()
        //String connString = "Data Source=contacts.db"; from current directory
        String connString = "Data Source=C://temp/contacts.db"; //from specific location
        using (SQLiteConnection conn = new SQLiteConnection(connString))
            Console.WriteLine("Opening Connection");
            Console.WriteLine("Creating 'Contacts' Table");
            using (SQLiteCommand cmd = new SQLiteCommand(createSql, conn))
            Console.WriteLine("Query 'Contacts' Table");
            using (SQLiteCommand cmd = new SQLiteCommand(selectSql, conn))
                using (SQLiteDataReader dr = cmd.ExecuteReader())
                    while (dr.Read())
                        Console.WriteLine("  "+dr.GetString(dr.GetOrdinal("FirstName")) + " " + dr.GetString(dr.GetOrdinal("LastName")));