Skip to content

Instantly share code, notes, and snippets.

View HarryMcCarney's full-sized avatar

Harry McCarney HarryMcCarney

View GitHub Profile
#r "nuget: Feliz.ViewEngine"
#r "nuget: Plotly.NET"
open Feliz.ViewEngine
open System
open System.Diagnostics
open System.IO
open Plotly.NET
#r "nuget: FSharp.FGL, 0.0.4"
#r "nuget: FSharp.FGL.ArrayAdjacencyGraph"
open FSharp.FGL
open FSharp.FGL.ArrayAdjacencyGraph
let vertices =
[ for i=01 to 3 do (i,i) ]
let edges =
//http://allendowney.github.io/ThinkBayes2/chap03.html#the-dice-problem
#r "nuget: FSharp.Stats, 0.4.12-preview.1"
open FSharp.Stats
open FSharp.Stats.Distributions
let normalise (dist: Map<'a, float>) =
let totalProbability = dist |> Map.toSeq |> Seq.sumBy snd
dist |> Map.map (fun k v -> v / totalProbability)
(*
Exercise: In Major League Baseball, most players have a batting average between .200 and .330, which means that their probability of getting a hit is between 0.2 and 0.33.
Suppose a player appearing in their first game gets 3 hits out of 3 attempts. What is the posterior distribution for their probability of getting a hit?
https://colab.research.google.com/github/AllenDowney/ThinkBayes2/blob/master/notebooks/chap04.ipynb#scrollTo=LB4DESMrA0bs
*)
#r "nuget: FSharp.Stats, 0.4.12-preview.1"
#r "nuget: Plotly.NET"
#r "nuget: FSharp.Stats, 0.4.12-preview.1"
#r "nuget: fsharp.data"
#r "nuget: Plotly.NET"
open FSharp.Data
open FSharp.Stats
open FSharp.Stats.Distributions
open Plotly.NET
let normalise (dist: seq<'a * float>) =
// Think Bayes - Allen B. Downey
//Chapter 1 - Probability
#r "nuget: FSharp.Stats, 0.4.12-preview.1"
#r "nuget: fsharp.data"
#r "nuget: Plotly.NET"
open FSharp.Data
open FSharp.Stats
open System.Collections.Generic
let mutable terms = new Dictionary<int64, int>()
let isPower2 (x: int64) =
x &&& (x - 1L) = 0
let addSeqToDict (t: int64 array) =
t
|> Array.rev
|> Array.mapi(fun i x -> terms.TryAdd(x,(i+1) ))
////Helper functions////
let getTrianglesAndCoPrimes n =
if n % 2 = 0 then (n*(n+1)/2, (n/2), (n+1))
else (n*(n+1)/2,((n+1)/2), n)
let getDivisors n =
let rec loopAndCheck n i divisors =
if i > n/2 then divisors |> Set.ofArray
elif n % i = 0 then loopAndCheck n (i+1) (Array.append divisors [|i|])
else loopAndCheck n (i+1) divisors
#r "nuget: FSharp.Data"
#r "nuget: Microsoft.Data.SqlClient"
#r "nuget: Dapper"
open Microsoft.Data.SqlClient
open Dapper
open FSharp.Data
open System.Threading
open System
@HarryMcCarney
HarryMcCarney / selco.http
Last active December 1, 2021 16:27
This gist includes HTTP calls to get information on Selco product catalog
### INSTALL REST CLIENT FOR VISUAL STUDIO CODE AND OPEN THIS FILE TO MAKE THE REQUESTS
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
### 001 - Get verticals
GET /graphql?query=query%20category(%24id%3AInt%3D7)%20%7Bcategory(id%3A%24id)%7Bdescription%20name%20url_key%20url_path%20breadcrumbs%7Bcategory_id%20category_name%20category_level%20category_url_key%20__typename%7Dchildren_count%20children%7Binclude_in_menu%20url_path%20url_key%20id%20display_mode%20image%20thumbnail%20children_count%20product_count%20name%20__typename%7Dexcerpt%20meta_description%20meta_title%20image%20thumbnail%20id%20__typename%7D%7D&operationName=category&variables=%7B%22id%22%3A6%7D HTTP/1.1
Host: www.selcobw.com
authority: www.selcobw.com
accept: */*
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
content-type: application/json