Skip to content

Instantly share code, notes, and snippets.

View bohdanszymanik's full-sized avatar

Bohdan Szymanik bohdanszymanik

  • Wellington, New Zealand
View GitHub Profile
// running in fable.io/repl to check performance on 32 bit win 7 with chrome
type Agent<'T> = MailboxProcessor<'T>
let agent =
Agent.Start(fun inbox ->
async { while true do
let! msg = inbox.Receive()
printfn "got message '%s'" msg } )
agent.Post "hello"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bohdanszymanik
bohdanszymanik / scoopadoopa.ps1
Created December 23, 2016 02:15
Get scoop.sh behind the corporate proxy fw
set-executionpolicy unrestricted -s cu
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials
iex ($browser).downloadstring('https://get.scoop.sh')
@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);"
@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 }}
# 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"
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
// 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''
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
#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)