Skip to content

Instantly share code, notes, and snippets.

View Thorium's full-sized avatar

Tuomas Hietanen Thorium

View GitHub Profile
@Thorium
Thorium / BlockChain.fs
Last active September 27, 2021 02:26
Using NBitcoin to create private BlockChain with F# (FSharp)
// This is just an initial example / tech-demo.
#if INTERACTIVE
#I "./../packages/NBitcoin/lib/net45/"
#I "./../packages/Newtonsoft.Json/lib/net45"
#r "NBitcoin.dll"
#r "Newtonsoft.Json.dll"
#else
module BlockChain
#endif
@Thorium
Thorium / graphgen.fs
Created December 9, 2016 20:23
How you can programmatically use GraphViz from F#
// 1. Install: http://www.graphviz.org/Download..php
//
// 2. Add <appSettings> under <configuration> to app.config/web.config
// Add Nuget / Paket: GraphViz.NET
//
// 3. Add under <configuration><appSettings>:
// <add key="graphVizLocation" value="C:\Program Files (x86)\Graphviz2.38\bin" />
//
// Add references to System.Configuration.dll and System.Drawing.dll
@Thorium
Thorium / Emojis.fs
Created June 3, 2020 15:04
Coding with Emojis
// In Windows you can press WindowsKey+"." to open Emoji menu.
let ``🍕`` = "🥓" + "🍍"
//val ( 🍕 ) : string = "🥓🍍"
@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 / 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 / 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 / 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 / example.txt
Last active December 13, 2017 22:40
File parsing, based on multiple lines, using recursive pattern matching with many :: (cons) operator
== MyItem 1 ==
...some content...
Total: 10
Success
== MyItem 2 ==
...some content...
Total: 2
Failed