Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
isaacabraham / SimpleTimetableParser.fs
Last active January 28, 2020 23:29
Parses ATOC timetable data in CIF format for UK national rail timetables (available at http://data.atoc.org/how-to). The parser has two main entry methods - loadStations, which parses the .MSN file into stations, and loadTimetables, which parses the .MCA portion of the ATOC dataset into timetables (and also uses the output of loadStations to cre…
open System
// Basic data structures
[<Flags>]
type Day =
| None = 0
| Mon = 1
| Tue = 2
| Wed = 4
| Thu = 8
@isaacabraham
isaacabraham / asyncsample.fs
Created October 9, 2013 22:20
Pretty much the same sample as asyncsample.cs except in F#...
open System
open System.Diagnostics
open System.Net
open System.Threading
let consolePrinter =
MailboxProcessor.Start(fun agent ->
async {
while true do
let! message = agent.Receive()
@isaacabraham
isaacabraham / AzureTypeProviderSample1.fs
Last active December 25, 2015 13:19
Azure Type Provider Sample #1 - illustrates how to use the basic features of it.
type account = Elastacloud.FSharp.AzureTypeProvider.AzureAccount< "accountName","accountKey" >
// Downloads LeagueTable.csv as an Async<string>
let textAsyncWorkflow = async {
let! text = account.Containers.container1.``LeagueTable.csv``.Download()
printfn "%s" (text.ToLower())
return text
}
// Downloads binary.zip as an Async<Byte[]>
@isaacabraham
isaacabraham / signalrIoc.cs
Last active December 25, 2015 22:19
SignalR with IoC
/// <summary>
/// Uses Unity to create Hubs - and ONLY Hubs.
/// </summary>
// Register with GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => unityHubActivator);
public class UnityHubActivator : IHubActivator
{
private readonly IUnityContainer container;
public UnityHubActivator(IUnityContainer container)
@isaacabraham
isaacabraham / constraintprob.fs
Last active December 27, 2015 04:59
Why doesn't this work!!!
// A simple word-count mapper
let wordCountMapper (line : string) =
line.ToLower().Split(' ')
|> Seq.filter (not << System.String.IsNullOrEmpty)
|> Seq.map (fun word -> word, word)
// lets try to plug it into the Microsoft Hadoop API so we can call e.g. let mapper = createStreamingUnitExecutor wordCountMapper
let createStreamingUnitExecutor mapper =
// object expression to create a new implementation of the MapperBase based on the function provided
let mapperBase =
@isaacabraham
isaacabraham / AwaitingMultiplePolls.cs
Created November 22, 2013 00:17
Async await pattern over a long-running polling operation
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Foo();
Console.ReadLine();
}
@isaacabraham
isaacabraham / awaitabledemo.cs
Last active December 29, 2015 05:19
Illustrates how to create an awaitable without using Task.
namespace AwaiterDemo
{
class Program
{
static void Main(string[] args)
{
Foo();
Console.ReadLine();
}
@isaacabraham
isaacabraham / sodokuSolver.fs
Created December 4, 2013 21:06
An example F# Sodoku solver using a variation of the backtracking algorithm.
open System
module Seq =
/// Evaluate a predicate over every item. If the predicate passes, return Some x, otherwise return None.
let toOptional predicate =
Seq.map(fun item -> if predicate item then Some item else None)
type Cell =
{ Index : int
X : int
@isaacabraham
isaacabraham / parseFootballResults.fs
Last active January 2, 2016 02:59
Reading CSV results from football-data.co.uk into F#
open FSharp.Data
open System
type Outcome = | Win | Lose | Draw
type Location = | H | A
type Result =
{ Date : DateTime
Opponent : string
Location : Location
Score : int * int
@isaacabraham
isaacabraham / downloadEmails.fs
Last active January 2, 2016 03:08
Illustrates how to download the headers of the emails in an email folder and write the contents to disk.
open System
open System.IO
open System.Net
type FootballMail =
{ From : string * string
Subject : string
Date : string }
let emailWriter =