Skip to content

Instantly share code, notes, and snippets.

// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
open System.IO
open SevenZip
open System
SevenZipCompressor.SetLibraryPath(@"path/to/7z.dll")
let dir = @"files/path/..."
open System
open Prelude
open System.Text.RegularExpressions
open System.IO
open System.Windows
let sw = Diagnostics.Stopwatch()
/////////////////////////////////////////////////////////////
let countsymbols (s : string) =
type Variable = Strings of float | Number of float * float * float
type Probability = Map<string , Map<string,Variable> * float>
let inline pairAdd (a,b) (c,d) = a + c , b + d
let inline div (a,b) = if b = 0. then a else a / b
let strOfVar = function Strings(n) -> n | _ -> 0.
@sir-deenicus
sir-deenicus / worldbank-country-ranking.fs
Last active September 13, 2017 05:05
A hastily constructed script to rank countries according to some criteria and generate an html table.
open FSharp.Data
let data = WorldBankData.GetDataContext()
let scoreArr = [|
"Household final consumption expenditure per capita (constant 2000 US$)", (-7.5, 50000.);
"Intentional homicides (per 100,000 people)", (-20., 1000.);
"Fixed broadband Internet subscribers (per 100 people)", (9.5, 100.);
"Burden of customs procedure, WEF (1=extremely inefficient to 7=extremely efficient)", (6., 7.);
"CPIA transparency, accountability, and corruption in the public sector rating (1=low to 6=high)", (6., 6.);
"GINI index", (-5., 100.);
@sir-deenicus
sir-deenicus / jatexgplus.js
Last active December 18, 2015 14:28
This is a very simple chrome plugin that allows latex to render in google plus. Installation is (simple). Download the zipped plugin from google drive [1](exactly same, conveniently packaged), go to extensions, check developer mode, unzip to a folder and click Load Unpacked Extenstion to load the folder [1] clickable link is a comment below.
var injectMathJax = document.createElement('script');
var typeSet = document.createElement('script');
var style=document.createElement('style');
//modified: css https://github.com/christianp/mathjax-bookmarklet/blob/master/bookmarklet.js
style.innerText = '.MathJax .mn {background: inherit;} .MathJax .mi {color: inherit;} .MathJax .mo {background: inherit;}';
injectMathJax.type = 'text/javascript';
injectMathJax.src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
@sir-deenicus
sir-deenicus / hyphenate.fs
Last active January 1, 2016 12:09
Hyphenation algorithm used by Tex.
type HyphTree =
| Node of (int [] option) * Map<char, HyphTree>
| Empty
let insertpattern tree pattern =
let chars = pattern |> Seq.filter (Char.IsNumber >> not) |> Seq.toArray
let points = Text.RegularExpressions.Regex.Split(pattern, "[.a-z]") |> Array.map (fun c -> let b, i = Int32.TryParse c in if b then int i else 0)
let rec bt t = function
| i when i = chars.Length -> Node(Some points, Map.empty)
| i ->
open System
open FSharp.Data
type GplusPost = FSharp.Data.JsonProvider<"gplusposttemplate.json">
type GplusSearch = FSharp.Data.JsonProvider<"gplusSearchTemplate.json">
type GplusCommentList = FSharp.Data.JsonProvider<"gplusCommentListTemplate.json">
let googlePlusFunc key url parse (mapItems) (next) takeAtATime maxtake query =
let download token choice =
try
Algeria 5.86 0.93
Angola 5.09 0.88
Argentina 6.39 0.66
Australia 8.67 0.32
Austria 7.73 0.55
Azerbaijan 5.6 0.495
Bangladesh 5.07 1.0
Belgium 7.51 0.33
Brazil 6.52 0.865
Bulgaria 5.73 0.335
@sir-deenicus
sir-deenicus / rps2 output
Last active September 13, 2017 23:55
Regret Minimization on Rock, Paper, Scissors (Games with gifts and no gifts)
LEARNED STRATEGY
Move | Move Probability
---- | ----------------
R | 0
P | 0.999
S | 0
T | 0
LEARNED STRATEGY VS FIXED ADVERSARY
@sir-deenicus
sir-deenicus / rps output
Last active September 13, 2017 05:35
Regret Minimization. Nash Equilibrium for Rock Paper Scissors
STRATEGY VS STATIC ADVERSARY
Move | Move Probability
-------- | ----------------
Rock | 0
Paper | 1
Scissors | 0
STRATEGY VS STATIC ADVERSARY
Player 1 | Player 2 | Prob 1 | Prob 2 | Joint Prob | Player 1 Util | Player 2 Util