Skip to content

Instantly share code, notes, and snippets.

View bohdanszymanik's full-sized avatar

Bohdan Szymanik bohdanszymanik

  • Wellington, New Zealand
View GitHub Profile
@bohdanszymanik
bohdanszymanik / MarketMaker.fsx
Last active December 30, 2015 21:29
Playing with Hanson's Logarithmic Scoring Rule (LMSR) Market Maker. Created as an agent because I wanted to simulate market behaviour with large numbers of agents and watch how price changes.
(*
From http://blog.oddhead.com/2006/10/30/implementing-hansons-market-maker/
*)
open System
// ---------------------------------------------------
// first off some helper functionality to report messages as events, copied straight off Don Syme's blog: http://blogs.msdn.com/b/dsyme/archive/2010/01/10/async-and-parallel-design-patterns-in-f-reporting-progress-with-events-plus-twitter-sample.aspx
@bohdanszymanik
bohdanszymanik / wsdlServiceExample.fs
Created May 19, 2015 01:00
Example F# wsdlService typeprovider call with authentication and extra attributes (max message size)
open System
open System.ServiceModel
open Microsoft.FSharp.Linq
open Microsoft.FSharp.Data.TypeProviders
(* bit dumb but because service requests authentication, and we can't do that in the wsdlservice tp, we have to download wsdl, load it up locally, set
binding up properly, then use tp *)
open System.Net
open System.IO
open System.Text
@bohdanszymanik
bohdanszymanik / wsdlMoreDifficult.fs
Created August 11, 2015 21:49
wsdlservice call when there's proxy's, a need to change http parameters, authentication etc etc
open System
open FSharp.Data
open System
open System.ServiceModel
open Microsoft.FSharp.Linq
open Microsoft.FSharp.Data.TypeProviders
(* execute the following commented stuff only once to get the wsdl, then leave commented
(* bit dumb but because service requests authentication, and we can't do that in the wsdlservice tp, we have to download wsdl, load it up locally, set
#r @"packages\NodaTime\lib\net35-Client\NodaTime.dll"
open NodaTime
SystemClock.Instance.Now
let pattern = NodaTime.Text.LocalDateTimePattern.CreateWithInvariantCulture("MM/dd/yyyy HH:mm")
pattern.Parse("11/05/2014 21:15")
let dt s = DateTime.ParseExact(s, "d/MM/yyyy h:mm:ss tt", CultureInfo.CurrentCulture)
let (>|>) x f =
let timer = new System.Diagnostics.Stopwatch()
timer.Start()
let r = f x
printfn "Elapsed Time: %i" timer.ElapsedMilliseconds
r
[1..1000]
>|> List.map (fun x -> [1..x] |> List.sum)
>|> List.max
// getting to grips with PrintfFormat
//let sscanf (pf:PrintfFormat<_,_,_,_,'t>) s : 't =
let explorePF (pf:PrintfFormat<'printer,'state,'residue,'result,'tuple>) s : string =
pf.Value
explorePF "(%s %% % %i)" "(somestring)"
explorePF "(%s %% %z %i)" "(somestring)" // error FS0741: Unable to parse format string 'Bad format specifier: 'z''
open System
open System.IO
open System.Text.RegularExpressions
open System.Globalization
(*
For this example let's say we have data describing the processing of a batch of steps eg something like this:
BatchId
Start DateTime, End DateTime, Step Description
# needed to count number of rows populated in filenet database docversion and generic tables for a filenet migration analysis
# wasn't able to use sql server client tools so had to do this in powershell...
function Invoke-SQL {
param(
[string] $sqlCommand = $(throw "Please specify a query.")
)
$connectionString = "Server = someServer,4000; Network Library=DBMSSOCN; Initial catalog = somedb; User Id = someUser; Password = somePassword; Connection Timeout = 120"
@bohdanszymanik
bohdanszymanik / parallelSample.ps1
Created December 22, 2016 20:43
Very cool - Split-PipeLine is a very handy tool!
1..10 | . {process{ $_; sleep 1 }}
function giveMeTwo {2}
$log = "Barney"
$src = "c:\temp"
1..10 | Split-Pipeline -Count 2 -Variable log,src -Function giveMeTwo {process{ write-host "Value: $_ from thread $([System.Threading.Thread]::CurrentThread.ManagedThreadId) for $log, $src"
write-host $(giveMeTwo)
sleep 1 }}
@bohdanszymanik
bohdanszymanik / sqlCmd.ps1
Created December 22, 2016 20:46
Get-Credential example for sql command
$Cred = Get-Credential -Message "Enter database credentials" -UserName $DBUser
function Invoke-SqlCmd {
param(
[string] $sqlCommand = $(throw "Please specify a query.")
)
$connectionString = "Server = someServer,1234; Network Library=DBMSSOCN; Initial catalog = $db; User Id = $($Cred.UserName); Password = $($Cred.GetNetworkCredential().Password);"