Skip to content

Instantly share code, notes, and snippets.

View Thorium's full-sized avatar

Tuomas Hietanen Thorium

View GitHub Profile
@Thorium
Thorium / Program.fs
Last active April 24, 2019 18:33
Creating graphical visualisation of a Markov chain
module GraphVizSample
open GraphVizWrapper
open GraphVizWrapper.Commands
open GraphVizWrapper.Queries
open System
open System.Configuration
open System.Drawing
open System.IO
@Thorium
Thorium / uaparse.fs
Last active February 19, 2019 03:24
Parsing UserAgent strings with FSharp
open System
open System.IO
open System.Net
open System.Text.RegularExpressions
let req = HttpWebRequest.Create "https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml"
let resp = (new StreamReader(req.GetResponse().GetResponseStream())).ReadToEnd()
let lines = resp.Split( [| Environment.NewLine; "\r"; "\n"; "\r\n" |], StringSplitOptions.RemoveEmptyEntries)
/// Minimal YAML-file parsing
let yamlParse =
@Thorium
Thorium / bitbucket-pipelines.yml
Last active May 14, 2018 12:29
Bitbucket pipelines test to build FSharp repository
# Take FSharp docker image and run Fake build script using Paket FSharp and Gulp.
image: fsharp:latest
pipelines:
default:
- step:
script:
- echo "Runs on branches that don't have specific pipeline."
# Install general utilities for building
- apt-get -qq update
@Thorium
Thorium / ftps.fs
Created December 5, 2017 14:34
FTPS download and upload a file
// FTPS = SSL encrypted FTP.
// SFTP = FTP over SSH.
// Set this as config, as the server may change the certificate.
let ``trusted server certificate hash`` = "603780E732DB12D0F6BA434BA8E04D141904A165"
open System
open System.IO
open System.Net
open System.Net.Security
@Thorium
Thorium / sftp.fs
Created November 20, 2017 19:28
SFTP with SSH.Net
// #r "../packages/SSH.NET/lib/net40/Renci.SshNet.dll"
open Renci.SshNet
open System.IO
/// FSharp Async wrapper for SSH.NET SFTP
type SftpClient with
member x.ListDirectoryAsync path =
Async.FromBeginEnd((fun(iar,state) ->
@Thorium
Thorium / DecisionTree.fs
Last active May 16, 2018 15:32
Wine-quality decision-tree using Accord.Net from F#
(*
Install-Package FSharp.Data
Install-Package Accord
Install-Package Accord.MachineLearning
Install-Package Accord.Math
Install-Package Accord.Statistics
*)
#if INTERACTIVE
@Thorium
Thorium / extension.fs
Created May 8, 2017 19:07
Visual Studio 2017 extension: Displaying Light Bulb Suggestions
// Example follows this, translated to FSharp:
// https://msdn.microsoft.com/en-us/library/dn903708.aspx
// Just instead of copy&pasting C#, add a new F# class library and paste this code to there,
// then add that to reference to your C#-project.
// If you want to deploy without C# project, see e.g. this:
// You need to use some VSIX-package to deploy the code:
// https://github.com/fsharp-vsix/FsVSIX
@Thorium
Thorium / ml.fs
Created March 28, 2017 10:39
Using machine learning tool Accord.Net from F#
// This example uses the same data and methods as
// http://accord-framework.net/docs/html/T_Accord_Statistics_Models_Regression_LogisticRegression.htm
#I @"./packages"
#r @"FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll"
#r @"Accord.3.4.0/lib/net45/Accord.dll"
#r @"Accord.MachineLearning.3.4.0/lib/net45/Accord.MachineLearning.dll"
#r @"Accord.Math.3.4.0/lib/net45/Accord.Math.Core.dll"
#r @"Accord.Math.3.4.0/lib/net45/Accord.Math.dll"
#r @"Accord.Statistics.3.4.0/lib/net45/Accord.Statistics.dll"
@Thorium
Thorium / BtcBalance.fs
Created February 2, 2017 21:54
Get Bitcoin wallet account balance by public key
// Using FSharp.Data
type WalletData =
FSharp.Data.JsonProvider<
"""{"unspent_outputs":[{"value":9000000000},{"value":10}]}""">
let getBalance publicKey =
let balance =
try
WalletData.Load(
@Thorium
Thorium / BtcPrice.fsx
Created February 2, 2017 18:14
Bitcoin current price data from blockchain.info
//Using FSharp.Data
type BtcData = FSharp.Data.JsonProvider<"""{
"USD":{"15m":1.1,"last":1.1,"buy":1.1,"sell":1.1,"symbol":"$"},
"EUR":{"15m":1.1,"last":1.1,"buy":1.1,"sell":1.1,"symbol":"€"},
"GBP":{"15m":1.1,"last":1.1,"buy":1.1,"sell":1.1,"symbol":"£"}
}""">
let prices = BtcData.Load("https://blockchain.info/ticker")
//prices.Eur.Buy : val it : decimal = 923.52M (at 02/02/2017)
//prices.Gbp.Sell : val it : decimal = 794.61M (at 02/02/2017)