Tuesday, June 10, 2014

Swift Day1 in Playground





Optional typing

Operator Overload

Simple String Format
Option
Switch/Pattern Matching
let vegetable = "red pepper" switch vegetable { case "celery": let vegetableComment = "Add some raisins and make ants on a log" default: let vegetableComment = "Everything tastes good in soup" }

Thursday, March 7, 2013

Start FoundationDB with Scala (Update to Version 1.0.2)


So, FoundationDB has released version 1.0.2 already.  If you haven't heard about FoundationDB, it is basically a key-value storage with strong transaction support and rich built-in data model.



FoundationDB deals with bytes directly, this is like HBase.

Java SDK:

libraryDependencies += "com.foundationdb" % "fdb-java" % "1.0.0"

Hello World example in Scala




https://github.com/yuanw/foundation-DB-tutorial

Tuesday, April 3, 2012

Using Akka Actor in Play2.0

I 've been learning Play framework 2.0 for a while. The documentation did a relatively decent job, it has some minor typos and doesn't cover all the framework features, which are totally understandable since it is still a working progress. The samples ship with the framework are really really good, you can really learn lots from the samples, and of course there is scala doc. However, if you like me: a scala newbie doesn't have too much experiences with Akka, SBT, and other scala libraries play based on; Learning play seems to be an overwhelming task at the beginning. This blog attempts to give an introduce how to use Akka Actor in play 2.0.


Content:
1. How to create actor in Akka 2.0
2. How to wire Akka Actor with play 2.0
3. Commutating between Play Action and Akka Actor via Future and Promise



1. Akka 2.0 (this part base on Akka Actor(scala) Documentation)

I assume you have some understanding about Actor model, if not, dont worry there are plenty articles give you a nice and short introduce about actor model, like this one .

Akka 2.0 uses a different way to create actor: you have to create an actor via Actor System, right now dont worry too much about Actor system: just think it as a container of Akka actors to manage the life cycles of all the Akka actors within the system.









MyActor is your Actor's class name, Props (akka.actor.Props) "is a ActorRef configuration object", and name is an optional parameter to build Actor Path, so you can address your actor by its path. In this tutorial, we won't use this feature.

2. How to wire Akka with Play (this part based on Play Integrate with Akka Doc)
Since Play 2.0 has build-in support for Akka 2.0, so you dont have to create Actor System by yourself







Play docs forgot to mention current, it "implicitly import the current running application in the context.", so play can wire your app with Akka correctly.

3. Commutating between Play Action and Akka Actor via Future and Promise (this part base on Akka Future Documentation and Play Integrate with Akka Doc )

I assume you understand the concept of Future and Promise, they are just generic "data structure to retrieve the result of some concurrent operation". To get Future from an Akka Actor, we have to implicit convert our ActorRef into AskAbleActorRef by import akka.pattern.ask, according to the Akka documentation, it seems you dont have to give a timeout parameter, but according my experience, you have to give a timeout parameter either directly or implicitly, no sure whether it is a bug. 


Monday, February 6, 2012

quick note on how to deploy play 2.0 RC on Herkou

1. make sure Procfile is at the app root with
web: target/start -Dhttp.port=${PORT}
2. compile your app into execute: sbt clean compile stage (a file start created by targe folder)

3. git push heroku master



Sources: http://devcenter.heroku.com/articles/scala#deploy_to_herokucedar
https://github.com/playframework/Play20/wiki/ProductionHeroku

Wednesday, October 20, 2010

GWT 2.1 RC-1 MVP introduction

I used GWT at 1.2.x for a while and did a little project on that. and then never use GWT too much. Recently, GWT 2.1 RC 1 is released. I think why not pick it up. This blog aims to summary some related infos and my tips on GWT2.1 RC 1 MVP (Modle-View-Presenter) subject.

Since Ran Ryan's gwt best practices talk at Google IO 09, the gwt community has some implementations over the MVP ideas: GWTP and MVP4g . GWT team decided to put MVP into the gwt-2.1, named as MVP framework (Activity and Place)

As every other new framework or technology, GWT MVP framework has many terms and some of them are not so intuitive. However, Google alway offers documentations and examples.

Here is a list of google references on this subject:

Sample app helloMVP

Large Scale app development and MVP part-I and part-II

How to use google-gin in the helloMVP example (on-going discussion on google group)

Thomas Broyer on his blog wrote a serie of article over the MVP concept

In this blog, I am going to try explain the concept very briefly and give a example.

GWT-MVP has three major concepts: Place, Activity, and View.

Place:
one place is one bookmark-able URL of your GWT app, each place has its own String token, and each place can be accessed via a URL. For example, you application URL is localhost:8888, your place A's string token is "home", the URL for this place is localhost:8888#home.
Place is just a java class, you put state information into it.

Activity:

IMO really a bad naming, Activity is a presenter in MVP term. one place should point to a activity. It is possible to point multiple place to the same activity. As mentioned, place can contains state, so you choose activity to response different state.

View:
In GWT MVP, Activity supposes to fetch the view, and add the view to the page.

so Place-->Act-->View-->Other Places

to glue act and place together, we need PlaceHistoryMapper , ActivityMapper, and ActivtiyManager. PlaceHistroyMapper is mapping string token to place, ActivtiyMapper is mapping place to activity, and ActivityManager is charge off handle the PlaceChangeEvent and execute the activity.

Next blog will give a example using gwt mvp framework