Skip to content

Instantly share code, notes, and snippets.

View jamessdixon's full-sized avatar

Jamie Dixon jamessdixon

View GitHub Profile
open System
let getLastDirectory (filePath:string) =
let lastSlashPosition = filePath.LastIndexOf(char 47)
let totalLength = filePath.Length
let tokenLength = totalLength - lastSlashPosition - 1
filePath.Substring(lastSlashPosition+1,tokenLength)
let subDirectoryInfos (path:string) =
let baseDirectoryInfo = System.IO.DirectoryInfo(path)
open System
open System.IO
open System.Drawing
type PictureFile = {FileName:string; NumberOfColumns:int; NumberOfRows:int}
let createTargetDirectory (fileName:string) =
let targetDirectory = "//Users//jamesdixon//Desktop//Images//" + fileName
let directoryinfo = new DirectoryInfo(targetDirectory)
match directoryinfo.Exists with
@jamessdixon
jamessdixon / CSharpToFSharp
Created August 31, 2018 12:17
Convert Auto-Generatd C# classes to F# Types
open System
open System.IO
open System.Collections.Generic
let path = @"C:\Git\..."
let folderInfo = System.IO.DirectoryInfo(path)
let files = folderInfo.GetFiles("*.cs")
let parseClass (values: IEnumerable<string>) =
let className =
@jamessdixon
jamessdixon / gist:b351af631ad02853bb51f40086361c43
Created July 4, 2017 01:27
UWA for IoT targeting a RP2: Blinkey
public sealed partial class MainPage : Page
{
GpioPin _pin = null;
Int32 _pinValue = 0;
public MainPage()
{
this.InitializeComponent();
Loaded += MainPage_Loaded;
}
type Customer = {Name:string; Email:string}
type Input = {Customer:Customer; MaxNameLength:int}
type Result<'t> =
| Good of 't
| Bad of string
let bind switchFunction =
fun twoTrackInput ->
match twoTrackInput with
@jamessdixon
jamessdixon / Programmic NLog Example Using FSharp
Created December 29, 2016 16:13
Programmic NLog Example Using FSharp
#r "../packages/NLog.4.4.1/lib/net45/NLog.dll"
open NLog
let config = new Config.LoggingConfiguration()
let target = new Targets.ColoredConsoleTarget("ConsoleTarget")
config.AddTarget(target)
let rule = new Config.LoggingRule()
@jamessdixon
jamessdixon / MakeDecemberTenAgain
Created December 22, 2016 00:46
New Day Of Year Based On A 10 Month Calendar
open System
let getNewDate dayOfYear =
["Jan";"Feb";"Mar";"Apr";"May";"Jun";"Sep";"Oct";"Nov";"Dec"]
|> Seq.mapi(fun i m -> if i%2=0 then m, [1..36] else m, [1..37])
|> Seq.map(fun (m,ad) -> ad |> Seq.map(fun d -> m,d))
|> Seq.collect(fun a -> a)
|> Seq.mapi(fun i d -> i, d )
|> Seq.tryFind(fun (i,d) -> i = dayOfYear)
@jamessdixon
jamessdixon / Age and Sex Analysis Of Microsoft USA MVPs
Created December 6, 2016 03:03
Age and Sex Analysis Of Microsoft USA MVPs
#r "WindowsBase.dll"
#r "System.Net.Http.dll"
#r "PresentationCore.dll"
#r "../packages/FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll"
open System
open System.IO
open System.Web
open System.Net
@jamessdixon
jamessdixon / TheCountedStateMap
Last active August 29, 2015 14:24
The Counted State Map
the.counted <- read.csv("./Data/TheCountedWithGeo.csv")
summary(the.counted)
#http://stackoverflow.com/questions/13420700/r-ggplot2-ggmap-concentric-circles-as-points
library(ggplot2)
library(maps)
all.states <- map_data("state")
plot <- ggplot()
plot <- plot + geom_polygon(data=all.states, aes(x=long, y=lat, group = group),
@jamessdixon
jamessdixon / TAMGeoAndTheCounted
Created July 1, 2015 19:09
TAMGeoLocation and TheCounted Dataset
#r "../packages/FSharp.Data.2.2.2/lib/net40/FSharp.Data.dll"
open System
open System.IO
open System.Text
open FSharp.Data
[<Literal>]
let geoLocationSample = "..\Data\TAMUHttpGet.json"
type GeoLocationServiceContext = JsonProvider<geoLocationSample>