søndag 11. juli 2010
torsdag 1. juli 2010
ScalaQuery Documentation
You can find it at: http://wiki.github.com/tbje/scala-query
onsdag 9. juni 2010
Emacs and file encoding
C-x RET f coding-system RET
Read file again with another encoding:
C-x RET c coding-system RET M-x revert-buffer RET
torsdag 22. april 2010
ReCaptcha Lift integration
I had some issues making it work well with Lift so I decided to blog about it (sharing is caring).
The standard approach described here (code under) didn't show up in Opera so I chose to go with the AJAX API.
The "html"
Recaptcha.create() brings up the captcha. When the form is submitted we call setHidden() to set the hidden lift form elements.
<lift:msgs/> displays messages set with S.error.
On the server side we verify the response by calling the reCaptcha API.
Binding using the -%> operator binds the attributes from the html (here the essential id attributes).
The following was tested on Google App Engine and might need some modifications to work other places.
mandag 12. april 2010
mandag 29. mars 2010
CometActor: What happens when render fails
I also found out that when the render fails, it will display defaultXml which if you do some binding is not valid xml.
I later came to that overriding defaultXml must be a good way to make my CometActor more fault tolerant.
The problem in the code above is that we try to bind using the newly defined defaultXml and not the NodeSeq from the template. How can we get hold of template xml? Easy we just call super.defaultXml:
Adding scripts to CometActor in Lift
If you ever wondered how to include javascript in the head section or how to include other content in the body when using a CometActor the solution is to override fixedRender:
The resulting html:
Notice that Lift is using two div's, and during a reRender(false) only the inner one is updated.
Unfortunately the Alert doesn't take a JsCmd, I would prefer writing:
mandag 1. mars 2010
Maven and Scalatest
I started experimenting with ScalaTest some days ago tempted by the nice looking Feature Specs over here.
mvn scala:cc is continuously compiling my scala code - I wanted to be able to call something like mvn test -Dtest=MyTest from command line as well as for maven to run all my test suites when building.
This is how:
Install the maven-scalatest-plugin:
git clone git://github.com/teigen/maven-scalatest-plugin.git
cd maven-scalatest-plugin && mvn clean install
Update the pom.xml
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>com.jteigen</groupId>
<artifactId>maven-scalatest-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<filereports>NCXEHLOWFD file/constrained.txt,file/full.txt</filereports>
<xmlreports>xml</xmlreports>
<htmlreports>html/report.html</htmlreports>
</configuration>
</plugin>
Run tests:
mvn test will now exectue all the scala test suites found after building the project.
However the build is not really necessary when mvn scala:cc is running at the same time.
mvn com.jteigen:maven-scalatest-plugin:1.0-SNAPSHOT:test will only execute the tests.
What if you don't want to run all the suites?
mvn com.jteigen:maven-scalatest-plugin:1.0-SNAPSHOT:test -Dsuite=mypack.MySuite