Skip to content

Instantly share code, notes, and snippets.

View PatrickMcDonald's full-sized avatar

Patrick McDonald PatrickMcDonald

View GitHub Profile
@PatrickMcDonald
PatrickMcDonald / FParsecTutorial.fsx
Created February 4, 2015 16:58
FParsec tutorial
#I @"..\packages\FParsec.1.0.1\lib\net40-client"
#r "FParsec.dll"
#r "FParsecCS.dll"
open FParsec
// 4.2 Parsing a single float
let test (p:Parser<_,_>) str =
match run p str with
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text]
"Icon"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
00,46,00,69,00,6c,00,65,00,73,00,5c,00,53,00,75,00,62,00,6c,00,69,00,6d,00,\
65,00,20,00,54,00,65,00,78,00,74,00,20,00,33,00,5c,00,73,00,75,00,62,00,6c,\
00,69,00,6d,00,65,00,5f,00,74,00,65,00,78,00,74,00,2e,00,65,00,78,00,65,00,\
2c,00,30,00,00,00
"AppliesTo"="System.FileName:?*"
' http://support.microsoft.com/kb/291296/en-us
' http://superuser.com/questions/130592/how-do-you-force-excel-to-quote-all-columns-of-a-csv-file
' - change integer to long indexing
' http://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba
' - output utf8 content
Sub QuoteCommaExport()
' Dimension all variables.
Dim DestFile As String
Dim FileNum As Integer
@PatrickMcDonald
PatrickMcDonald / fox.fsx
Created September 13, 2014 00:24
@fsibot
let i="ing" in let d="d"+i in let m=[|d;d;d;d|]|>String.concat "-" in sprintf "R%s-%ser%sed%s!" i m i i//What does the fox say?
let rec foldWhere (f:'State -> 'T -> 'State) acc p list =
match list with
| [] -> acc
| head::tail ->
let acc = if p head then (f acc head) else acc
foldWhere f acc p tail
//let countWhere<'T> = foldWhere (fun s (x:'T) -> s + 1) 0
let countWhere p l = List.fold (fun s x -> if p x then s + 1 else s) 0 l
[<CompiledName("SortByDescending")>]
let sortByDescending f xs =
match xs with
| [] | [_] -> xs
| _ ->
let compareByDescending x y = compare (f y) (f x)
sortWith compareByDescending xs
[<CompiledName("SortDescending")>]
let sortDescending xs =
[<CompiledName("SortByDescending")>]
let sortByDescending keyf source =
checkNonNull "source" source
mkDelayedSeq (fun () ->
let keyf = System.Func<_,_>(keyf)
let res = System.Linq.Enumerable.OrderByDescending(source, keyf)
res :> seq<_>)
[<CompiledName("SortDescending")>]
let sortDescending source =
let rec change denominations amount =
match denominations with
| [] -> 0
| _ when amount = 0 -> 1
| head :: tail when amount < head -> change tail amount
| head :: tail -> (change denominations (amount - head)) + (change tail amount)
change [50; 20; 10; 5; 2; 1] 100;;