<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-19967453</atom:id><lastBuildDate>Wed, 09 Oct 2024 09:21:46 +0000</lastBuildDate><category>Java</category><category>WPF</category><category>WPF Forum Questions</category><category>C#</category><category>C++</category><category>Tools</category><category>Tutorial</category><category>Code Snippets</category><category>Interviews</category><category>Programming</category><category>.NET 3.5</category><category>Article</category><category>Groovy</category><category>Dave</category><category>early adoption</category><category>freelance work</category><category>projects</category><category>screencasts</category><category>DLR</category><category>IronPython</category><category>Java 7</category><category>SWT Browser</category><category>Tricks</category><category>VB</category><category>closures</category><category>startup</category><title>Musings of a Software Developer</title><description>by Krishna Vangapandu</description><link>http://krishnabhargav.blogspot.com/</link><managingEditor>noreply@blogger.com (Krishna Bhargava Vangapandu)</managingEditor><generator>Blogger</generator><openSearch:totalResults>195</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>5</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-19967453.post-5650456315760701021</guid><pubDate>Wed, 11 Jun 2014 19:50:00 +0000</pubDate><atom:updated>2014-06-11T12:50:28.995-07:00</atom:updated><title>Moved to Github</title><description>Moved my blog from here to &lt;a href=&quot;http://krishnabhargav.github.io/&quot;&gt;krishnabhargav.github.io&lt;/a&gt;</description><link>http://krishnabhargav.blogspot.com/2014/06/moved-to-github.html</link><author>noreply@blogger.com (Krishna Bhargava Vangapandu)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-19967453.post-6766773263506654096</guid><pubDate>Fri, 03 Jan 2014 14:45:00 +0000</pubDate><atom:updated>2014-01-03T06:46:29.768-08:00</atom:updated><title>Few handy things to know in Go Library (Command line arguments, Reflection, Setting Bits, Hash functions)</title><description>&lt;h4&gt;
Command line arguments in Go&lt;/h4&gt;
&lt;div&gt;
In order to access the command line arguments passed to a Go executable, we work with the &quot;flag&quot; package from the standard Go library. Shown below is an example of passing command line arguments.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;go run cla.go Krishna&lt;/pre&gt;
Or if you have an executable obtained from go build, you can run it as&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;./cla Krishna &lt;/pre&gt;
Shown below is an example go snippet that accesses the first argument passed &amp;amp; prints it.&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import (
    &quot;fmt&quot;
    &quot;flag&quot;
)

func main() {
 //Without the call to Parse(), arguments may not be accessed
 flag.Parse()
 fmt.Printf(&quot;%s\n&quot;,flag.Arg(0))
}&lt;/pre&gt;
Notice that you will have to invoke the call to flag.Parse() without which you will not be able to access the arguments.&lt;br /&gt;&lt;br /&gt;
&lt;h4&gt;
Reflection support in Go&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
We take the previous example, add some code for reflection which will help us understand how reflection library may be used. Just some simple example without having to go deep. For that, read this &lt;a href=&quot;http://blog.golang.org/laws-of-reflection&quot;&gt;post from the official Go blog&lt;/a&gt;. 
&lt;br /&gt;
&lt;br /&gt;
So what is the type returned by flag.Arg(0) ? We will start from there and go use some functions.&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import (
 &quot;fmt&quot; //regular format package
 &quot;flag&quot; //package from command line arguments
 &quot;reflect&quot; //package for reflection
)

func main() {
 //Without the call to Parse(), arguments may not be accessed
 flag.Parse()
 fmt.Printf(&quot;%s\n&quot;,flag.Arg(0))

 passed := flag.Arg(0)
 //TypeOf actually returns a Type type
 fmt.Println(&quot;typeof : &quot;,reflect.TypeOf(passed))

 //ValueOf actually returns a Value
 fmt.Println(&quot;valueof : &quot;,reflect.ValueOf(passed))

 //Example functions from the Value type
 fmt.Println(&quot;type: &quot;,reflect.ValueOf(passed).Type())
 fmt.Println(&quot;kind: &quot;, reflect.ValueOf(passed).Kind())
 fmt.Println(&quot;interface:&quot;, reflect.ValueOf(passed).Interface())
}

&lt;/pre&gt;
&lt;h4&gt;
Big Integer &amp;amp; Set Bits&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
In the future post, I would like to implement a Bloom filter in Go but for that I will need to know how to do the following:&lt;/div&gt;
&lt;div&gt;
- Create a big number and set some bit &quot;x&quot; to 1 or 0.&lt;/div&gt;
&lt;div&gt;
- Accept a string, convert it to byte array, then hash the byte array.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To support the above, I wanted to see how simple big numbers would work. I am only looking enough to support my purpose.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Big Numbers (multi-precision numbers) are supported using &quot;math/big&quot; package in Go library. Shown below is an example code that does that.&lt;/div&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import ( 
   &quot;fmt&quot;
   &quot;math/big&quot;&lt;/pre&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;   &quot;unsafe&quot;
)

func main() {
 
 //create a new big integer
 filter := big.NewInt(0)

 fmt.Println(&quot;filter value: &quot;,filter)
 
 //accessing the sizeof from unsafe package
 fmt.Println(&quot;size of : &quot;,unsafe.Sizeof(filter))
 
 //example of how to cast uintptr to int
 filter.SetBit(filter,int(unsafe.Sizeof(filter)*8)-1,1)
 
 fmt.Println(&quot;filter after setbit last to 1 : &quot;,filter)
}
&lt;/pre&gt;
&lt;br /&gt;
The above example shows a few things:&lt;br /&gt;
- Creating an instance of big.Int using the NewInt() call.&lt;br /&gt;
- Accessing the size of the big.Int using unsafe package exported SizeOf() function&lt;br /&gt;
- SizeOf() returns uintptr and we convert that to integer - that is a good example of casting&lt;br /&gt;
- How to set bit on the big.Int using SetBit&lt;br /&gt;&lt;br /&gt;
&lt;h4&gt;
Working with Hash functions&lt;/h4&gt;
&lt;div&gt;
Example below demonstrates the following&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;how to convert a string to a byte array&lt;/li&gt;
&lt;li&gt;how to use FNV Hash from the standard Go library&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import (
 &quot;fmt&quot;
 &quot;hash/fnv&quot;
)

func main() {
        //Create a hash fnv function
 hash := fnv.New32()
 
 name := &quot;Krishna&quot;

 //converting string to byte array
 namebytes := []byte(name)

 fmt.Println(&quot;hash reset : &quot;,hash.Sum32())
 
 hash.Write(namebytes)

 fmt.Println(&quot;hash of Krishna : &quot;,hash.Sum32())

 hash.Reset() //resets the hash

 fmt.Println(&quot;hash reset : &quot;,hash.Sum32())

 //write again
 hash.Write(namebytes)
 
 fmt.Println(&quot;hash of Krishna : &quot;, hash.Sum32())
}
&lt;/pre&gt;
Hash libraries in the Go &quot;hash&quot; package implements the Hash interface. The implementations in the standard Go library as of this time are adler32, crc32, crc64, fnv-1/fnv-1a. The above example creates an instance of FNV hash, writes a byte array to it and then gets the value through Sum32() call. You can &quot;forget&quot; what is written to it by Reset() function which will allow you to reuse the hash instance.&lt;br /&gt;
&lt;br /&gt;
I am newly learning Go and along the way sharing some things that I learnt. If you know of a better way to accomplish what I have shared here, please feel free to comment.</description><link>http://krishnabhargav.blogspot.com/2014/01/few-handy-things-to-know-in-go-library.html</link><author>noreply@blogger.com (Krishna Bhargava Vangapandu)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-19967453.post-1855722919294644814</guid><pubDate>Thu, 02 Jan 2014 04:30:00 +0000</pubDate><atom:updated>2014-01-02T05:40:54.493-08:00</atom:updated><title>Working with &quot;Packages&quot; in Go language</title><description>Packages in Golang&lt;br /&gt;
&lt;br /&gt;
The specification states that all source files for a package be stored in the same directory.&lt;br /&gt;
You can import a package as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;import &quot;fmt&quot;
&lt;/pre&gt;
&lt;br /&gt;
In this case, the Printf method may be accessed as fmt.Printf(). All other identifiers exported by the package is also accessible as fmt.XXXX().&lt;br /&gt;
&lt;br /&gt;
You can also do the following.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;import f &quot;fmt&quot;&lt;/pre&gt;
In this case, the qualifier is &quot;f&quot; instead of the default &quot;fmt&quot;. So you access as &quot;f.Printf()&quot;.&lt;br /&gt;
&lt;br /&gt;
One other way is the following.
&lt;br /&gt;
&lt;pre&gt; import . &quot;fmt&quot; &lt;/pre&gt;
In this case, you dont need a qualifier for the exported identifiers from the fmt package.
You may also use the blank identifier (underscore : _) as the qualifier name for cases where you wish the initialize the package but not necessarily import its exported identifiers.
&lt;br /&gt;
Source files of a package have an init() function. See below for more details.&lt;br /&gt;
The previous example of a simple Web Server is now split into two files

&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;//GoWebServer.go
package main

import f &quot;fmt&quot;

//init() is a special function that gets initialized.
func init(){
 f.Printf (&quot;Package Initialized\n&quot;)
}

func main() {
 f.Printf(&quot;Web Server will be started at port 8080\n&quot;)
 runWebServer()
}
&lt;/pre&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;//WebServerHelper.go

package main

import (
 . &quot;fmt&quot;
 &quot;io&quot;
 web &quot;net/http&quot;
)

func init(){
 Printf(&quot;Initializing WebServerHelper.go \n&quot;)
}

func runWebServer(){
 rootHandler := web.HandlerFunc(func(w web.ResponseWriter, r *web.Request) {
  io.WriteString(w, &quot;Hi there, I love &quot;+r.URL.Path)
 })

 srv := web.Server{
  Handler: rootHandler,
  Addr:    &quot;:8080&quot;,
 }
 srv.ListenAndServe()
}
&lt;/pre&gt;
Few things that I learnt when trying to make this work.&lt;br /&gt;
- You need to specify all the files required for your main program to build properly. So you may&lt;br /&gt;
&lt;pre&gt;go build&lt;/pre&gt;
Or you may run&lt;br /&gt;
&lt;pre&gt;go build *.go&lt;/pre&gt;
- You can also specify output to be generated as&lt;br /&gt;
&lt;pre&gt;go build -o output/gowebserver&lt;/pre&gt;
Or be more explicit&lt;br /&gt;
&lt;pre&gt;go build -o output/gowebserver *.go&lt;/pre&gt;
- Go complier does not like if a package is imported but not used. This is good. I cannot tell how annoying i find C# using statements that are just there but no one really uses them.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Notice that both the files have an init() function defined and when I build everything and run the program, the output is as follows:&lt;/div&gt;
&lt;pre&gt;Package Initialized
Initializing WebServerHelper.go 
Web Server will be started at port 8080
&lt;/pre&gt;
&lt;br /&gt;
Such init() functions may be defined multiple times even in the same source file &amp;amp; the execution order is unspecified/undefined. So we should not write our initialization logic based or the execution order.
&lt;br /&gt;
And init() cannot be called by anyone else. Packages are initialized only once. So if you import packages P &amp;amp; Q but Q also imports P, then P is initialized only once.&lt;br /&gt;
&lt;br /&gt;
Package initialization is comprised of variable initialization (package level variables are all assigned initial values) &amp;amp; invocation of init() functions - performed one package at a time in a single go routine.&lt;br /&gt;
&lt;br /&gt;
See below for a basic program that indicates the above said sequence - variable initialization followed by init() method.
&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import &quot;fmt&quot;

//x := 2000
var x int = 2000

func init(){
 var y int = x
 fmt.Printf(&quot;X value is %d\n&quot;,y)
}

func main(){ }
&lt;/pre&gt;
&lt;br /&gt;
x is a global variable (which by the way cannot use the shortcut notation that is commented) that is initialized to 2000 and that is what gets printed when the program is executed.&lt;br /&gt;
&lt;h4&gt;
Local Packages in Go&lt;/h4&gt;
When you say
&lt;br /&gt;
&lt;pre&gt;import &quot;fmt&quot; &lt;/pre&gt;
the package &quot;fmt&quot; is looked for in the standard Go tree. Then it is looked for in &quot;$GOPATH/pkg&quot; directory where $GOPATH is the environment variable set to some directory on your machine. Commands such as &quot;go get&quot; also looks for this directory. You can read more about it &lt;a href=&quot;http://golang.org/pkg/go/build/&quot;&gt;here (look for Go path)&lt;/a&gt;.

So what about local packages - the one you do not want to put in GOPATH but leave it in the current directory for your application? To make this work, I renamed the package declaration (which originally was main) for the WebServerHelper.go as 
&lt;br /&gt;
&lt;pre&gt;package ws&lt;/pre&gt;
Then I created a folder with the same name as the package &amp;amp; placed the .go file in the folder. Then my import statements on the GoWebServer.go (the main file) has changed to 
&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;import (
 f &quot;fmt&quot;
 ws &quot;./ws&quot;
)
&lt;/pre&gt;
Notice the &lt;b&gt;&quot;./ws&quot;&lt;/b&gt; declaration. So the import &quot;XXX&quot; statement says look for &quot;XXX&quot; file path. So without &quot;./&quot; it was looking in standard GO tree, then it looks at GOPATH. If there was a &quot;./&quot;, it was just looking at the local directory. You may also give absolute paths. Also you don&#39;t need to build this directory specially. Just have your main file compile and you are good. 
&lt;br /&gt;
&lt;br /&gt;
One other things that I had to change in the code to make the application work as before.&lt;br /&gt;
- In packages, if your function is to be exported, then it should start with upper case. In general, a field or a function or other identifiers within a package that starts with upper case letter are exported. 
&lt;br /&gt;
&lt;br /&gt;
So if you are trying to make the previous code run (after the directory changes as described above), you will get the following&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;./GoWebServer.go:15: cannot refer to unexported name ws.runWebServer&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;./GoWebServer.go:15: undefined: ws.runWebServer&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
So just change the name of the function to &quot;RunWebServer&quot; &amp;amp; it becomes exported and ready to use.&lt;br /&gt;
&lt;br /&gt;
That&#39;s it for now!</description><link>http://krishnabhargav.blogspot.com/2014/01/working-with-packages-in-go-language.html</link><author>noreply@blogger.com (Krishna Bhargava Vangapandu)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-19967453.post-9080992900591398737</guid><pubDate>Tue, 31 Dec 2013 05:36:00 +0000</pubDate><atom:updated>2013-12-30T21:36:13.918-08:00</atom:updated><title>Writing some Go! code</title><description>This post is my notes when writing some code in Go lang. To start off, I will write a Hello World program in Go language. &amp;nbsp;See below. &lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import &quot;fmt&quot;

func main(){
 messageToPrint := &quot;Welcome to Go!&quot;
 fmt.Printf(messageToPrint + &quot;\n&quot;)
}
&lt;/pre&gt;
&lt;br /&gt;
Now to run this, you can do one of the following :
&lt;br /&gt;
&lt;pre class=&quot;powershell&quot; name=&quot;code&quot;&gt;go run HelloWorld.go
&lt;/pre&gt;
OR &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;powershell&quot; name=&quot;code&quot;&gt;go build HelloWorld.go
&lt;/pre&gt;
In the first case, &quot;go run&quot; compiles the program and runs it. It does not create an executable as such. (It could be creating a temporary executable somewhere.) The second command actually builds an executable which you can run.

Go also has a tool called &quot;gofmt&quot; which you can run directly as gofmt or can run as 

&lt;br /&gt;
&lt;pre class=&quot;powershell&quot; name=&quot;code&quot;&gt;go fmt HelloWorld.go &lt;/pre&gt;
. 

The formatting tool formats your source code so that it matches the Go-defined formatting. This is a good thing as each one of us need not invent our own coding conventions.

Gofmt can also be used to perform some code refactoring. In order to perform a rename variable, the following command does the trick.

&lt;br /&gt;
&lt;pre class=&quot;powershell&quot; name=&quot;code&quot;&gt;gofmt -l -w -r &#39;messageToPrint -&amp;gt; mesg&#39; ./HelloWorld.go &lt;/pre&gt;
The above command would rename the messageToPrint variable as mesg. In general, you pass &#39;pattern -&amp;gt; replaceWith&#39; style of commands when using the -r option.

More information on what gofmt -r can be used for is available in this &lt;a href=&quot;http://www2.gli.cas.cz/home/cejchan/go/gofmt-r.pdf&quot;&gt;presentation&lt;/a&gt; &amp;nbsp;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;Writing a Web Server in Go!&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The following code snippet shows a Web Server that is written in Go! and also shows how to write anonymous functions in Go!&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import (
 &quot;fmt&quot;
 &quot;net/http&quot;
)

func main() {
 fmt.Printf(&quot;Web Server will be started at port 8080\n&quot;)
        //See below for anonymous function
 http.HandleFunc(&quot;/&quot;, func(w http.ResponseWriter, r *http.Request) {
  fmt.Fprintf(w, &quot;Hi there, I love %s!&quot;, r.URL.Path)
 })
 http.ListenAndServe(&quot;:8080&quot;, nil)
}
&lt;/pre&gt;
&lt;br /&gt;
Now a better way (in my opinion) to write the same code as above is shown below.&lt;br /&gt;
&lt;pre class=&quot;c&quot; name=&quot;code&quot;&gt;package main

import (
 &quot;fmt&quot;
 &quot;net/http&quot;
)

func main() {
 fmt.Printf(&quot;Web Server will be started at port 8080\n&quot;)
 rootHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  fmt.Fprintf(w, &quot;Hi there, I love %s!&quot;, r.URL.Path)
 })

 srv := http.Server{
  Handler: rootHandler,
  Addr:    &quot;:8080&quot;,
 }

 srv.ListenAndServe()
}

&lt;/pre&gt;
In this example, we are actually creating an instance of a Http Server as opposed to the previous example where the http global helper methods were used to start the Http Web Service.&lt;br /&gt;
&lt;br /&gt;
I was just curious to see how well this naive web service performs. Using apache bench, when I run 10000 requests at concurrency level of 100-700, the sample (stupid) program can serve around 5000 requests/second on my age old laptop. Just for kicks, the server in Go is atleast 5 times faster for each request as compared to the nodejs http server.&lt;br /&gt;
&lt;br /&gt;
Back to Go! ..&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Package has to be &quot;main&quot; for your main program. Otherwise, it does not work.&lt;/li&gt;
&lt;li&gt;Passing -x flag to your helper commands such as &quot;go run&quot;, &quot;go fmt&quot; or &quot;go build&quot; will display the complete output and the commands internally executed.&lt;/li&gt;
&lt;li&gt;The &quot;go build&quot; has all compiler optimizations enabled.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description><link>http://krishnabhargav.blogspot.com/2013/12/writing-some-go-code.html</link><author>noreply@blogger.com (Krishna Bhargava Vangapandu)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-19967453.post-286509238759739163</guid><pubDate>Wed, 14 Nov 2012 04:22:00 +0000</pubDate><atom:updated>2012-11-13T20:32:56.752-08:00</atom:updated><title>Hello World! with Scala Web Application using Play 2.0 and Scalate</title><description>&lt;p&gt;In this post, we will look at how to make a hello-world web application in scala using the Play 2.0 Web Framework and change the template engine to work with Scalate. We assume your machine is all set up with Java and Scala configured. &lt;/p&gt; &lt;h3&gt;Step 1 : DOWNLOAD AND CONFIGURE Play 2.0&lt;/h3&gt; &lt;p&gt;Download the Play Framework 2.0 from &lt;a title=&quot;http://download.playframework.org/releases/play-2.0.4.zip&quot; href=&quot;http://download.playframework.org/releases/play-2.0.4.zip&quot;&gt;http://download.playframework.org/releases/play-2.0.4.zip&lt;/a&gt;. Then extract the zip file to some location. I put mine at C:\Development\tools\play-2.0.4\. &lt;em&gt;It is usually a good idea to leave the version number intact so as to easily know what version of any tool you are currently having on your machine.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;The configuration portion is pretty simple – &lt;strong&gt;Update your PATH environment variable to include the root directory of the play-2.0.4 folder which has the “play.bat” (I am running windows).&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;To verify, launch your command line or powershell and type the command “play”. You should see something like shown below.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9Wdd74JCkWxDfXnh8eOSRfzou9smnu41u6cNR7Hcc1OlMmq6EUQBo9rfzUYb2wmn7tfKKnrLO2OZzxEJZLQJfDGKL-e-noxJbLm3RRnHHMjJoLSn0TCHFNBxTdoKEKOv84ub2Mg/s1600-h/image%25255B3%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-sCHoCGEaCcGBwrM_K8cctTc3RobI_kjJRY46jb-6hRr5ZI-Rus7P5Pk_FPrtJIUErskRwXbPsD6NfTUCZw6syq6ZkTQzWUlTBi4q2ZChSTkyO8sWdR4fhwrXhLq-5sijluAQSQ/?imgmax=800&quot; width=&quot;369&quot; height=&quot;144&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;&lt;/h2&gt; &lt;h3&gt;Step 2 : CREATE A NEW PLAY 2.0 WEB APPLICATION&lt;/h3&gt; &lt;p&gt;Using command line (change directory – cd), go to a folder where you wish to place your application. Run the following command&lt;/p&gt; &lt;p&gt;&lt;strong&gt;play new helloworld-scalate&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Here helloworld-scalate will be my application name. &lt;/p&gt; &lt;p&gt;Then from the command line go into the “helloworld-scalate” folder. And then run the following command.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;play run&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The first time you run, it takes a few seconds to initialize the project and upon success, you will see on-screen instructions that the application is hosted at 9000 port on localhost.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYR_3ulfIqSme6oXI-IShqnbhytBRrFdhRwf9X6Sc2IE4Ny2-CzpJkX_XwlSNgfZ_Nt6ZcxOW31HIiG7r8m-AjH8r41HhOYYGkW5Hx3yGwn3m74Bc6Jxk_piqGRqOaVo4tOCnxvg/s1600-h/image%25255B8%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0LGr36K6N45IQ1PKU_rub9LwmsHnwQukDXQRbaS30-VCLVB77NkczXVC2NLEKmGtIQ5XqD4sE2AyLw-4wbfFAXA2kgtovxTQCX7ovEyHe1cL-9ZuJQW4-pHP73xvbGOnLUh67SQ/?imgmax=800&quot; width=&quot;603&quot; height=&quot;381&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Verify by opening your browser and loading &lt;a href=&quot;http://localhost:9000&quot;&gt;http://localhost:9000&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You should see a welcome page.&lt;/p&gt; &lt;h3&gt;&lt;/h3&gt; &lt;h3&gt;Step 3 : INTEGRATING SCALATE INT YOUR APPLICATION&lt;/h3&gt; &lt;p&gt;I found the proper instructions to do this &lt;a href=&quot;http://aftnn.org/2012/oct/01/play-20-and-scalate/&quot;&gt;here&lt;/a&gt;. But I will repeat them again.&lt;/p&gt; &lt;p&gt;Go to helloworld-scalate\project\Build.scala&lt;/p&gt; &lt;h4&gt;3.a Add the following lines to &lt;strong&gt;appDependencies&lt;/strong&gt;. &lt;/h4&gt;&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;&quot;org.fusesource.scalate&quot; % &quot;scalate-core&quot; % &quot;1.5.3&quot;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;What did we do? &lt;/strong&gt;What we are doing is to add a dependency on scalate-core in an SBT friendly style. Play 2.0 takes care of fetching this dependency through its repositories which is listed at helloworld-scalate\project\plugins.sbt&lt;/p&gt;&lt;br /&gt;&lt;p&gt;To verify if things are fine, go back to command line and run the command &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;play run&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You should see that SBT updates the dependencies. Just verify if your application can still be browsed from localhost:9000.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;&lt;/h3&gt;&lt;br /&gt;&lt;h4&gt;3.b Add ScalaIntegration.scala to helloworld-scalate\app\lib&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;You will need to create a folder “lib” inside helloworld-scalate\app folder. And then from the URL given below copy the content into a new file – ScalaIntegration.scala&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a title=&quot;https://raw.github.com/janhelwich/Play-2-with-Scala-and-Scalate/master/app/controllers/ScalateIntegration.scala&quot; href=&quot;https://raw.github.com/janhelwich/Play-2-with-Scala-and-Scalate/master/app/controllers/ScalateIntegration.scala&quot;&gt;https://raw.github.com/janhelwich/Play-2-with-Scala-and-Scalate/master/app/controllers/ScalateIntegration.scala&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This does the necessary bootstrapping such that you can now use scalate in the current project.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Run the “play run” command again and reload the page at localhost:9000 to make sure you haven’t made a mistake.&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;&lt;/h2&gt;&lt;br /&gt;&lt;h3&gt;Step 4 : UPDATE VIEWS &amp;amp; ACTION WITH TEMPLATE OF YOUR CHOICE&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Scalate supports multiple template engines like Jade, Mustache, Scaml. The documentation indicates that Scaml gives the best performance given the strongly typed nature. But I might have misread the docs so &lt;a href=&quot;http://scalate.fusesource.org/which.html&quot;&gt;read and check yourself&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;To do this, rename your files inside “helloworld-scalate\app\views” folder such that extension is changed from &lt;strong&gt;.scala.html&lt;/strong&gt; to &lt;strong&gt;.scaml.&lt;/strong&gt; Note that you will see two files – the layout file (main) and the view file (index).&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In the main.scaml, add the following code.&lt;/p&gt;&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;-@ var body: String&lt;br /&gt;-@ var title: String = &quot;Page&quot;&lt;br /&gt;&lt;br /&gt;%html&lt;br /&gt;  %head&lt;br /&gt;    %title= title&lt;br /&gt;  %body&lt;br /&gt;    != body&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In the index.scaml, add the following code. &lt;/p&gt;&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;-@ var message: String = &quot;Page&quot;&lt;br /&gt;/Layout template file given here&lt;br /&gt;-attributes(&quot;layout&quot;) = &quot;main.scaml&quot;&lt;br /&gt;&lt;br /&gt;%h1= message&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Notice that in the index.scaml, we specified that we want to apply the &lt;strong&gt;main.scaml&lt;/strong&gt; layout using the &lt;strong&gt;attributes(“layout”) &lt;/strong&gt;declaration.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You also need to change the application controller which is inside the helloworld-scala\app\controllers\application.scala&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The Application controller has an action called “index” which is the one that gets executed when you were loading the browser. We need to change this action such that it renders using Scalate instead of the default one.&lt;/p&gt;&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;package controllers&lt;br /&gt;&lt;br /&gt;import play.api._&lt;br /&gt;import play.api.mvc._&lt;br /&gt;&lt;br /&gt;object Application extends Controller {&lt;br /&gt;&lt;br /&gt;  def index = Action {&lt;br /&gt;    //Ok(views.html.index(&quot;Your new application is ready.&quot;))&lt;br /&gt;    Ok(Scalate(&quot;index.scaml&quot;).render(‘message -&amp;gt; &quot;Hello World&quot;))&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;As you can see in the index action, I commented the existing line added this one line.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Ok(Scalate(&quot;index.scaml&quot;).render(‘message-&amp;gt; &quot;Hello World&quot;)) &lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Please pay attention to the ‘&lt;strong&gt; &lt;/strong&gt;in front of the title. Here the &lt;strong&gt;&lt;u&gt;‘message&lt;/u&gt;&lt;/strong&gt; is a symbol literal. &lt;a href=&quot;http://daily-scala.blogspot.com/2010/01/symbols.html&quot;&gt;You can read more about them here.&lt;/a&gt;&amp;nbsp; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now run the “play run” command again and you should see plain html page that prints “Hello World”.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;I hope this step-by-step helped you get started with a new play 2.0 web application in Scala and also made you familiar with integrating the scalate engine. Note that the &lt;a href=&quot;http://aftnn.org/2012/oct/01/play-20-and-scalate/&quot;&gt;original url&lt;/a&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;which I mentioned earlier has the same steps but step 4 where default Scalate template type is specified in the &amp;lt;application folder&amp;gt;\conf\application.conf&lt;strong&gt; &lt;/strong&gt;is not performed. I skipped this step and it doesn’t appear that it will cause any problems. But again, after reading this tutorial, if you are a beginner, then you and I are at the same level so please feel free to explore more and learn. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Thanks!&lt;/p&gt;  </description><link>http://krishnabhargav.blogspot.com/2012/11/hello-world-with-play-20-and-scalate.html</link><author>noreply@blogger.com (Krishna Bhargava Vangapandu)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-sCHoCGEaCcGBwrM_K8cctTc3RobI_kjJRY46jb-6hRr5ZI-Rus7P5Pk_FPrtJIUErskRwXbPsD6NfTUCZw6syq6ZkTQzWUlTBi4q2ZChSTkyO8sWdR4fhwrXhLq-5sijluAQSQ/s72-c?imgmax=800" height="72" width="72"/><thr:total>2</thr:total></item></channel></rss>