Scalable and Flexible Machine Learning With Scala @ LinkedIn
How to determine browser type in JavaScript (for SharePoint 2010 sites)
According to the sad situation in nowadays front-end development, we have to check current browser type and version in JavaScript code and behave differently depend on that. There are many options to do so like this or this. But working in SharePoint 2010 environment you have one more, init.js defines browseris object (see on the picture below) which contains most of required data. Be free to rely on SharePoint in this case.

F# Weekly #10, 2013
One more week passed by, but this past week was full of interesting announcements from WebSharper and Tsunami IDE teams. Read more below:
News
- Manifesto for Not Only Object-Oriented Development
- Tsunami IDE was announced.
- “F# for C# Developers” by Tao Liu, is coming soon. Don’t miss it.
Videos
- “How F# Learned to Stop Worrying and Love the Data” by Tomas Petricek.
- Tomas Petricek Digs Deep into F#.
- “Interactive F# scripting in Excel without Visual Studio” by Tsunami.
- “How to create Excel User Defined Functions in F# and make them immediately available to Excel” by Tsunami.
- “Rhino 3D with F#” by Tsunami.
- “Linq to Hadoop with Type Providers” by Tsunami.
- “FSUG Meeting with Tomas Petricek” (Tomas Petricek discusses Agents in F#)
- “Phil Trelford on F# Mocking with Foq“
- “Functional DSLs for Biocomputation” by Colin Gravill
Blogs
- Mathias Brandewinder posted “On F# code readability“.
- Anton Tayanovskyy wrote about “Upcoming WebSharper Changes“.
- Steffen Forkmann shared “License all the things with Portable.Licensing 1.0“.
- Anton Tayanovskyy announced “WebSharper 2.5.2-alpha on AppHarbor“.
- Simon Cousins blogged “Why bugs don’t like F#“.
- Steffen Forkmann posted “New tasks for building Xamarin Components in FAKE – F# Make“.
- Loic Denuziere announced “WebSharper for Windows 8 Desktop“.
- Michael Newton blogged “Coding Hygiene: Moving From Project References to NuGet Dependencies“.
- Scott Banwart posted “A ‘Hello World’ introduction to testing in F#“.
- Richard Dalton wrote “Bowling Game Kata in F#“.
That’s all for now. Have a great week.
Previous F# Weekly edition – #9
F# Weekly #9, 2013
Welcome to F# Weekly,
A roundup of F# content from this past week:
News
- Xamarin Studio now has F# addin
- IntelliFactory is offerring free WebSharper licenses for MVP.
- Foq 0.8 was released.
- Canopy: F# web testing framework built on Selenium was presented.
- Ross McKinlay shared slides from “Microsoft Dynamics CRM & F#” talk.
- SharpDevelop 4.3 was released.
Videos
- “The F# 3.0 SQL Server Type Provider – Very Cool, and Very Useful” by Kit Eason.
- “F# magic” by Adam Granicz.
- “Domain Specific Languages in F#” by Tomas Petricek (slides and samples).
- “String Calculator TDD Kata With F# and NUnit” by Dave Fancher.
Blogs
- Lev Gorodinski wrote “Domain-Driven Design (DDD) With F# and EventStore: Projections“.
- Sergey Tihon blogged “F# Image Blurrer“.
- Steve Gilham posted “FsCheck is great for for native code too!“.
- Igor Kulman wrote about “F# on Azure: using Table Storage for logging“.
- Yan Cui published “DynamoDB.SQL – version 1.1.0 released“.
- Adil Akhter shared “SPOJ 346. Bytelandian Gold Coins (COINS) | with Dynamic Programming and F#“.
- Adil Akhter shared “SPOJ 8545. Subset Sum (Main72) | with Dynamic Programming and F#“.
- Don Syme posted “Thursday at F# London Meetup: The F# 3.0 SQL Server Type Provider – Very Cool, and Very Useful, plus F# 3.0 Dynamics CRM Type Provider“.
- Sergey Tihon blogged “ServiceStack: New API – F# Sample (Web Service out of a web server)“.
- Yan Cui posted “F# — XmlSerializer, Record types and [CLIMutable]“.
- Colin Bull presented “F# IKVM Type Provider“.
- Sebastian Waksmunzki wrote “F# and MS CRM 2011 follow-up“
- Dave Fancher posted “Custom Dark Colors for F# Depth Colorizer for VS2012“.
- Sergey Tihon blogged “ServiceStack: F# Client Application“.
- Alea.cuBase shared “Segmented scan in warp with packed head flag“.
- F# team posted “The Microsoft Dynamics CRM Type Provider Sample: Static Parameters“.
- Ross McKinlay wrote “F# meets the Raspberry Pi“.
- Scott Wlaschin announced “Computation Expressions” series.
That’s all for now. Have a great week.
Previous F# Weekly edition – #8
ServiceStack: F# Client Application
In the previous post “ServiceStack: New API – F# Sample (Web Service out of a web server)” we implemented a self-hosted service with ServiceStack. That service has multiple out-of-the-box endpoints, including a REST one.
The next interesting question is “How to call this service?”(preferably in a strongly-typed way). The answer is simple, ServiceStack team have already made this for us. We can reuse types that designed for server-side code to make client code prettier. ServiceStack provides a list of different service clients for client applications.
open System
open ServiceStack.ServiceHost
open ServiceStack.ServiceClient.Web
[<CLIMutable>]
type HelloResponse = { Result:string }
[<Route("/hello")>]
[<Route("/hello/{Name}")>]
type Hello() =
interface IReturn<HelloResponse>
member val Name = "" with get, set
let baseUri = "http://localhost:8080/"
// Option 1 : Json call
let jsonCall() =
let client = new JsonServiceClient(baseUri)
client.Post(Hello(Name="json"))
// Option 2 : Xml call
let xmlCall() =
let client = new XmlServiceClient(baseUri)
client.Post(Hello(Name="xml"))
// Option 3: Jsv call
let jsvCall() =
let client = new JsvServiceClient(baseUri)
client.Post(Hello(Name="jsv"))
[<EntryPoint>]
let main args =
printfn "Json call : %A" (jsonCall())
printfn "Xml call : %A" (xmlCall())
printfn "Jsv call : %A" (jsvCall())
Console.ReadLine() |> ignore
0
F# IKVM Type Provider
ServiceStack: New API – F# Sample (Web Service out of a web server)
Two weeks ago in F# Weekle #6 2013 I mentioned Don Syme’s “F# + ServiceStack – F# Web Services on any platform in and out of a web server” post. There were two samples of using ServiceStack from F#. One of these examples is given on ServiceStack wiki page in Self Hosting section. It is also detailed in Demis Bellot’s “F# Web Services on any platform in and out of a web server!” post.
Unfortunately, this example is already obsolete. Some time ago, ServiceStack released a brand new API that significantly changed programming approach, especially routing (for details see “ServiceStack’s new API design“). But I am happy to say that you can find an updated example below!
New design is more typed. In the previous version IService‘s methods returned the Object, but now Service returns concrete type that is defined by IReturn<T> interface of request message.
open System
open ServiceStack.ServiceHost
open ServiceStack.WebHost.Endpoints
open ServiceStack.ServiceInterface
[<CLIMutable>]
type HelloResponse = { Result:string }
[<Route("/hello")>]
[<Route("/hello/{Name}")>]
type Hello() =
interface IReturn<HelloResponse>
member val Name = "" with get, set
type HelloService() =
inherit Service()
member this.Any (request:Hello) =
{Result = "Hello," + request.Name}
//Define the Web Services AppHost
type AppHost() =
inherit AppHostHttpListenerBase("Hello F# Services", typeof<HelloService>.Assembly)
override this.Configure container = ignore()
//Run it!
[<EntryPoint>]
let main args =
let host = if args.Length = 0 then "http://*:8080/" else args.[0]
printfn "listening on %s ..." host
let appHost = new AppHost()
appHost.Init()
appHost.Start host
Console.ReadLine() |> ignore
0
For comparison, the previous version is:
open System
open ServiceStack.ServiceHost
open ServiceStack.WebHost.Endpoints
type Hello = { mutable Name: string; }
type HelloResponse = { mutable Result: string; }
type HelloService() =
interface IService with
member this.Any (req:Hello) = { Result = "Hello, " + req.Name }
//Define the Web Services AppHost
type AppHost =
inherit AppHostHttpListenerBase
new() = { inherit AppHostHttpListenerBase("Hello F# Services", typeof<HelloService>.Assembly) }
override this.Configure container =
base.Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}") |> ignore
//Run it!
[<EntryPoint>]
let main args =
let host = if args.Length = 0 then "http://*:1337/" else args.[0]
printfn "listening on %s ..." host
let appHost = new AppHost()
appHost.Init()
appHost.Start host
Console.ReadLine() |> ignore
0
Update: An example of ServiceStack New API for F# 2.0 users. F# 2.0 does not have val keyword / auto-properties which were used in the first example.
</pre>
open System
open ServiceStack.ServiceHost
open ServiceStack.WebHost.Endpoints
open ServiceStack.ServiceInterface
type Project() =
let mutable projectID = 0
let mutable projectName = ""
let mutable companyName = ""
let mutable projectStatus = ""
member this.ProjectID with get() = projectID and set(pid) = projectID <-pid
member this.ProjectName with get() = projectName and set(pn) = projectName <- pn
member this.CompanyName with get() = companyName and set(cn) = companyName <- cn
member this.ProjectStatus with get() = projectStatus and set(ps) = projectStatus <-ps
type ProjectResponse() =
let mutable projects = List.empty<Project>
member this.Projects with get() = projects and set(pr) = projects <- pr
[<Route("/Project/{ProjectName}")>]
type ProjectRequest() =
let mutable projectName = ""
interface IReturn<ProjectResponse>
member this.ProjectName with get() = projectName and set(n) = projectName <- n
type ProjectService() =
inherit Service()
member this.Any (request:ProjectRequest) =
ProjectResponse(
Projects = [Project(ProjectName=request.ProjectName, ProjectID=1, CompanyName="A")])
//Define the Web Services AppHost
type AppHost() =
inherit AppHostHttpListenerBase("Project F# Services", typeof<ProjectService>.Assembly)
override this.Configure container = ignore()
//Run it!
[<EntryPoint>]
let main args =
let host = if args.Length = 0 then "http://*:8080/" else args.[0]
printfn "listening on %s ..." host
let appHost = new AppHost()
appHost.Init()
appHost.Start host
Console.ReadLine() |> ignore
0
<pre>
F# Image Blurrer
Image blurring is a king of popular task during presentation preparation. For example, if you want show something but hide sensitive information. Of course you can buy Photoshop but it is too expensive for such a simple task. Also you can download Paint.NET, but this is not an option for F# geek – it is too easy=). It is much better to write something by yourself (Binaries are available as well as source code).
open System
open System.IO
open System.Drawing
open System.Drawing.Imaging
let blur (image:Bitmap) blurSize =
let blurred = new Bitmap(image.Width, image.Height)
use graphics = Graphics.FromImage(blurred)
let rectangle = Rectangle(0, 0, image.Width, image.Height)
graphics.DrawImage(image, rectangle, rectangle, GraphicsUnit.Pixel);
for X in [0..image.Width-1] do
for Y in [0..image.Height-1] do
let (r,g,b,c) =
[Math.Max(0, X-blurSize)..Math.Min(image.Width-1, X+blurSize)]
|> Seq.fold (fun sum x ->
[Math.Max(0, Y-blurSize)..Math.Min(image.Height-1, Y+blurSize)]
|> Seq.fold (fun (r,g,b,c) y ->
let p = blurred.GetPixel(x,y)
(r + (int)p.R, g + (int)p.G, b + (int)p.B, c+1)
) sum
) (0,0,0,0)
blurred.SetPixel(X, Y, Color.FromArgb(r/c, g/c, b/c));
blurred
[<EntryPoint>]
let main argv =
try
printfn "argv = %A" argv
let (fileName, blurSize) =
match argv with
| [|fileName|] -> (fileName, 3)
| [|fileName; size|] ->
match Int32.TryParse(size) with
| (true, blurSize) when blurSize > 0 -> (fileName, blurSize)
| _ -> failwithf "Incorrect blurSize '%s'" size
| _ -> failwith "Incorrect parameters. Please enter 'fileName' and 'blurSize'"
printfn "FileName:%s\nBlurSize:%d" fileName blurSize
if (not(File.Exists(fileName)))
then failwithf "File '%s' does not exist." fileName
use inputStream = new MemoryStream(File.ReadAllBytes(fileName));
use source = new Bitmap(Image.FromStream(inputStream));
printfn "Processing..."
use result = blur source blurSize
printfn "Saving..."
let resultFileName =
sprintf "%s_%dblurred.jpg" (Path.GetFileNameWithoutExtension(fileName)) blurSize
result.Save(resultFileName, ImageFormat.Jpeg)
printfn "Done!"
with
| e ->
printfn "Exception : %s" e.Message
Console.ReadLine() |> ignore
0


F# Weekly #8, 2013
Welcome to F# Weekly,

The greatest event of this week and maybe of the year is 2013 MVP Global Summit. But while our MVPs make history, the new portion of news from this past week is waiting for you =).
News
- Steffen Forkmann presented experimental F# 4.0 installer.
- Interesting white paper from MS Research about F# 3.0 type provider.
- Fmat Open Source Numerical Library for F# was presented. (available on NuGet)
- Video from Keith Battocchi’s “Systems Information Programming Made Simple with the F# WMI Provider sample” talk was shared.
- Fsharpx 1.7.8 with Microsoft Dynamics CRM type provider is now on NuGet.
- Screenshot of F# on Xamarin Studio.
- MonoDevelop 4.0 was released.
- Mono 3.0.4 is out!
- Xamarin 2.0 reviewed: iOS development finally comes to Visual Studio.
Blogs
- Lev Gorodinski wrote “Domain-Driven Design With F# and EventStore“.
- Filip Ekberg posted “Decompiling .NET Applications“.
- Daniel Mohl shared materials from “Building Better Web Apps with F#” talk.
- Gaston Hillar blogged “More Information-Rich Programming with F#“.
- Adil Akhter shared “Collatz Problem a.k.a. 3n+1 Problem“.
- Phil Trelford posted “Connect All The Things – MVP Summit 2013“.
- Phil Trelford published “F# Eye For The C# Guy“.
- Gary Evans wrote “Option pricing in F# using the Explicit Finite Difference method“.
- Simon Cousins blogged “Does the language you choose make a difference?“.
- Yan Cui wrote about “AOP – string interning with PostSharp attribute“.
- Colin Bull presented “F# end to end“.
- Gustavo Guerra posted “F#, Windows Phone 7 & Visual Studio 2012“.
That’s all for now. Have a great week.
Previous F# Weekly edition – #7

