Archive

Archive for August, 2009

VanadiumJS.com is live !!!

August 26th, 2009 Daniello 21 comments

I’m pleased to announce that the first version of demo site presenting my client-side validation toolkit Vanadium is on the go.

Vanadium is declarative, client-side validation toolkit. There is no need for coding. Just use simple markup in side class attributes (or if you are HTML purist you may prefer to attach it as external configuration file in json format).

E.g. for required field one can define it as: <input type="text" class=":required“/>

It also make use of Ajax. E.g checking for username availability can be expressed as:

<input type="text" class=":ajax;/username_checker/check.json“/>

Another handy feature is hierarchical validation regions, lots of build-in validator types and easy way of creating custom ones.

I’ll appreciate any comments on it.

You can give it try on VanadiumJS.com. The code is open source and available on github.

Categories: Uncategorized Tags:

The BeeBole Erlang/Web Tutorial, Webmachine-Style

August 25th, 2009 Daniello 2 comments

Justin Sheehy posted here his webmachine version of a small but fun web application created originally in mochiweb by Hughes Waroquier from BeeBole. Hughes posted it in a form of neat screencast tutorial. It’s worth watching.

Justin’s version is dated from October 22, 2008 and at that time webmachine version was < 1.0. Since that time the webmachine progressed and API has changed. Moreover, Justin's great example is not a single file but rather code in-lined with post prose. His code has the static content delivery mixed-up with sticky notes resource. It also contained a security issue, which is using list_to_atom bif with arbitrary arguments coming from API user, potentially opening door to blow our erlang VM’s memory up (running out of atoms).

Recently I was asked by my friend to introduce him Erlang webdevelopment. I though immediately about webmachine and the sweet sticky notes tutorial so I decided to create working code of that stuff. I have reused my static resource for webmachine resulting in having separation of Ajax API and static content delivery, reducing the original stickyNotes_webresource.erl to 18 lines of code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-module(stickyNotes_webresource).
-export([init/1, process_post/2, allowed_methods/2]).
 
-include_lib("webmachine/include/webmachine.hrl").
 
init(Config) -> {{trace, "/tmp"}, Config}.
 
allowed_methods(ReqData, Context) ->
    {['POST'], ReqData, Context}.
 
 
process_post(ReqData, Context) ->
    Ps = mochiweb_util:parse_qs(wrq:req_body(ReqData)),
    Struct = mochijson2:decode(proplists:get_value("json", Ps)),
    Act = list_to_existing_atom(binary_to_list(struct:get_value(<<"action">>, Struct))), 
    Resp = wrq:merge_resp_headers([{"Content-Type", "application/json"}], ReqData),
    Resp2 = wrq:append_to_response_body(mochijson2:encode(notes:Act(Struct)), Resp),
    {true, Resp2, Context}.

The whole thing can be found at github.

Categories: Uncategorized Tags: