Computer Science Experimentation

Friday, August 10, 2012

Chat Application using Web Sockets Self-Hosted Server with F#

This post presents an Chat application in F# using the library:

The Chat application is based on Paul Batum example at:
The server is self-hosted.
I tried to make the application to be hosted in F# interactive console by making the configuration programmatically without success. Because of that, the F# application is compiled in order to use the App.cfg .

Using System.Json in F#


The System.Json library is only available for Silverligh environment.

A beta version for .NET can be obtained from Nuget (http://nuget.org/packages/System.Json).

This is the documentation at MSDN:
(http://msdn.microsoft.com/en-us/library/system.json(v=vs.95).aspx)

The System.Json namespace provides standards-based support for the serialization of JavaScript Object Notation (JSON).

JSON is a lightweight, text-based data interchange format that is used to serialize structured data for transmission over networks. It has three primitive data types: string, number, and Boolean. It has two data structures: array and object. An array is an ordered collection of values, where the value can be a JSON primitive, object or array. An object is an unordered set of key/value pairs. The key is a string and the value, as with the array, can be a JSON primitive, object, or array.

In this documentation, the serialized textual representation of JSON is referred to as “text-based JSON” to distinguish it from the deserialized representation of JSON as a Common Language Runtime (CLR) type, which is referred to here as a “JSON CLR type” or as a “JSON CLR object” if we are referring to an instance of the type.

JSON CLR types represent the three text-based JSON primitives with the JsonPrimitive type. The JsonType() property indicates which primitive is contained in the type instance: String, Number, or Boolean.

JSON CLR types represent the two text-based structured types with JsonArray and JsonObject. A JsonArray is an ordered sequence of zero or more JsonValue objects. A JsonValue is the JSON CLR representation of a JSON text-based value, which can be either a primitive or structured type. A JsonObject is an unordered collection of zero or more String/JsonValue pairs, which represent the key/value pairs of the text-based JSON object.

F# Example:

//Using System.Json.dll
//By Celso Axelrud on 8/10/2012

open System
open System.Collections.Generic

#r @"C:\Users\caxelrud\Documents\Visual Studio 2012\Projects\WebSck_Host_2\packages\System.Json.4.0.20126.16343\lib\net40\System.Json.dll"
open System.Json

let j="[{\"a\":\"foo\",\"b\":\"bar\"},{\"a\":\"another foo\",\"b\":\"another bar\",\"c\":100}]"
let jsonObj = JsonValue.Parse(j)

jsonObj.Count;;
(*> val it : int = 2 *)

jsonObj.[0].["a"].ReadAs<string>()
(*> val it : string = "foo" *)

jsonObj.[1].["c"].ReadAs<int>();;
(*> val it : int = 100 *)

//New Json object
let jsonNew = new JsonObject(new KeyValuePair<string,JsonValue>("mainValue", JsonPrimitive(12345)))

jsonNew.ToString()
(*> val it : string = "{"mainValue":12345}" *)


Saturday, August 4, 2012

Web Socket Self-Hosted Servers with WCF and F#

This post presents an Echo application using different libraries:
System.Net.Websockets (.NET 4.5)
Microsoft.ServiceModel.Websockets (beta)

Friday, May 18, 2012

Tests with F# and RMath.Net


This post reports results experiencing with Rmath.Net.

R (www.r-project.org/) is probably the most widely used statistical software.

The .NET wrapper is available at http://rmath.codeplex.com.

Check the full article at:
https://skydrive.live.com/#!/view.aspx?cid=BDC87EF39B001785&resid=BDC87EF39B001785%21365

F# Charting using FSharpChart Library

 This post  reports the results of experiencing with F# and:




Check the full article at:

https://skydrive.live.com/#!/view.aspx?cid=BDC87EF39B001785&resid=BDC87EF39B001785%21362

Tests with PIT-F# to Javascript Compiler


INTRODUCTION



This post reports several tests done with PIT ( http://pitfw.org ) v0.2.

The first set of examples is the original samples available in the PIT’s web page.
The other examples are collected from books as:

-         JavaScript for Web Developers (Nicholas et al.)
-         Pro HTML5 Programming (Lubbers et al.)
-         The Definitive Guide to HTML5 (Freeman)

Check the full article at:

Sunday, April 22, 2012

Real-time GUI with F# REST server

Introduction
This post presents a real-time Graphical User Interface (GUI) using HTML5 (SVG) client and a F# REST server. It is based on the following previous posts:

* WCF with F# interactive – Data Server example http://caxelrud.blogspot.com/2010/12/wcf-with-f-interactive-data-server.html

* Data and Historian Service using WCF and F# interactive - rev 2 http://caxelrud.blogspot.com/2011/05/data-and-historian-service-using-wcf.html

Graphics

The graphics were created using a web-based drawing tool (WYSIWYG) at http://www.diagram.ly/ and the result was exported as SVG. This tool includes several technical libraries for example the P&ID (Process and Instrumentation Diagram). 

Check the full article at:

https://skydrive.live.com/edit.aspx?cid=BDC87EF39B001785&resid=BDC87EF39B001785%21152#!/view.aspx?cid=BDC87EF39B001785&resid=BDC87EF39B001785%21348

(UNDER CONSTRUCTION ...)