Crawling mobile app stores with F#

Some time ago I needed a way to programatically search the Apple AppStore and Google Play Store to get some info about apps for a project. I decided to write an F# script for that task and later added support for Windows Phone Store.

Types

I wanted the script to be easily usable from outside of F# so first I created a type for the app.

type App = { Name: string; Package: string; IconUrl : string; StoreUrl: string}

I also needed a helper function to download data from the web. I used a classic WebClient with user agent set to Chrome, because the Windows Phone Store API requires a user agent header

[Read More]

Building Windows Phone apps with FAKE

FAKE is a build automation system with capabilities which are similar to make and rake. It is using an easy domain-specific language (DSL) so that you can start using it without learning F#. If you need more than the default functionality you can either write F# or simply reference .NET assemblies.

I have been using FAKE for quite some time now on some fairly complex projects for not only building but also running tests and creating and pushing Nuget packages and I really like. I decided to add FAKE build scripts to my Windows Phone apps to make the process of generating a XAP file for the Windows Phone Store easier.

The FAKE script I use can by used with any Windows Phone app, it will build all the projects and copy the XAP file to a release directory.

[Read More]

F# on Azure: using Table Storage for logging

Windows Azure finally has a good F# support. Creating F# Worker Roles is supported right from the wizzard in Visual Studio and you can create a F# Web Role using the F# C# MVC template. I decided to try it out and the first thing I needed to implement was logging. I decided for logging to Azure Table Storage.

I assume you have a basic idea of how Azure Table Storage works. If not, there is a good guide on the Windows Azure website.

The first thing you need to do is to define your log entry class. You need to create a class, Azure Table Storage does not work with F# records. In my case I want to store a timestamp, message and severity.

[<DataServiceKey("PartitionKey", "RowKey")>]
type LogEntity() =    
    let mutable partitionKey = ""
    let mutable rowKey = ""
    let mutable message = ""
    let mutable timestamp = DateTime.Now
    let mutable severity = ""  
    member x.PartitionKey with get() = partitionKey and set v = partitionKey <- v
    member x.RowKey with get() = rowKey and set v = rowKey <- v
    member x.Message with get() = message and set v = message <- v
    member x.Timestamp with get() = timestamp and set v = timestamp <- v
    member x.Severity with get() = severity and set v = severity <- v
[Read More]

Reading Excel sheets using F# without COM

I needed to create an utility that would read Excel 2010 files (.xlsx) and generate XML files from them according to some specific rules. The catch was that the utility needed to run on MacOS instead of Windows.

Reading and writing Excel files from .NET is very easy using the Microsoft.Office.Interop assemblies but they use Excel through COM and that makes them unusable outside of Windows. I found some 3rd party libraries for working with Excel and analzyed them with The Mono Migration Analzyer (MoMA). MoMA is a handy tool that analyzes .NET assemblies and tells you if they will run on Mono. Many of the Excel libraries I found were unusable for my use-case because they were using PInvoke calls. Only the ExcelPackage library runs on Mono.

I wanted to use the ExcelPackage from F# not C# so I wrote a very simple F# wrapper, that you can freely use. For now it contains just a few methods

[Read More]
excel  fsharp  mono 

Generating all permutations of a list … how hard can that be?

While reading an article that had nothing in common with programming I came upon a sudden need to find a way to generate all the permutations of a list, or more exactly a string (it is just a list of characters). As lazy as I am I tried to google a few examples of C# code that does exactly that. I was horrified that programmers could come up with the complicated ways I found. Not to mention programmers writing a ton of unit test and classes before actualy writing the code that solves to problem.

The problem is naturally recursive. All the permutations of a list of n items consit of each of the n items combined with all the permutations of the list without the actual item. So if you have a list of let’s say items (a,b,c), all the permutations are (a+permutation((b,c)) + (b+permutations((a,c))) + (c+permutations((a,b)).

First I came up with F# code to solve it, after some yield googling:

[Read More]