This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//core algorithm that returns a new zipper with the branch appended | |
let rec appendToTreeZipper (Loc (t,p) as l) (branch:list<string>) = | |
let rightSiblings = match p with | |
| Top(_) -> [] | |
| PathNode(_,_,_,rights) -> rights | |
let label = match t with | |
| Empty -> None | |
| TreeNode(lbl,_) -> Some(lbl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get the root tree from a zipper | |
let rec root (Loc (t, p) as l) = | |
match p with | |
| Top(_) -> t | |
| _ -> root (go_up l) | |
//creates zipper from a tree | |
let getZipper t = | |
match t with | |
| Empty -> Loc(Empty, Top("")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let PSUsableAssemblies = | |
AppDomain.CurrentDomain.GetAssemblies() | |
|> Array.filter (fun asm -> match asm.IsDynamic with | |
| true -> false | |
| false -> File.Exists asm.Location) | |
let FsToPs (codeDOMProviderPath:string) (fsCode:string) moduleName returnedVariableName = | |
let sb = new StringBuilder() | |
sb.AppendFormat("Add-Type -Path {0}",codeDOMProviderPath) |> ignore | |
sb.AppendLine("") |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myTest = "module dafuq | |
let x= 5 | |
" | |
//disk path to FSharp code dom provider | |
let codDomPath = @"<myPath>\FSharp.Compiler.CodeDom.dll" | |
let psCode = FsToPs codDomPath myTest "dafuq" "x" | |
//write script to file to test it. | |
use streamWriter = File.CreateText("simpleExample.ps1") | |
streamWriter.Write(psCode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -Path <myPath>\FSharp.Compiler.CodeDom.dll | |
$provider = New-Object Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider | |
$fsharpCode = @" | |
module dafuq | |
let x= 5 | |
"@ | |
$fsharpType = Add-Type -TypeDefinition $fsharpCode -CodeDomProvider $provider | |
[dafuq]::x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ExecPsScript<'T> script = | |
let runspaceConfiguration = RunspaceConfiguration.Create() | |
let runspaceAssemblies = runspaceConfiguration.Assemblies | |
let assembliesConfiguration = | |
PSUsableAssemblies | |
|> Array.map (fun asm -> new AssemblyConfigurationEntry(asm.FullName, asm.Location)) | |
assembliesConfiguration |> runspaceAssemblies.Append | |
assembliesConfiguration | |
|> Array.map (fun asm -> asm.FileName) | |
|> Array.map (fun path -> new TypeConfigurationEntry(path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<TestClass>] | |
type FsCeptionTests () = | |
[<TestMethod>] | |
member this.WithFactorial () = | |
let myTest = "module dafuq | |
let rec factorial n = | |
match n with | |
| 0 -> 1 | |
| 1 -> 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/BufferHeight 1000 powershell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters | |
{ | |
// instead of using the default validation (validating against a single issuer value, as we do in line of business apps (single tenant apps)), | |
// we turn off validation | |
// | |
// NOTE: | |
// * In a multitenant scenario you can never validate against a fixed issuer string, as every tenant will send a different one. | |
// * If you don’t care about validating tenants, as is the case for apps giving access to 1st party resources, you just turn off validation. | |
// * If you do care about validating tenants, think of the case in which your app sells access to premium content and you want to limit access only to the tenant that paid a fee, | |
// you still need to turn off the default validation but you do need to add logic that compares the incoming issuer to a list of tenants that paid you, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-BatchFile | |
{ | |
param([string]$Path, [string]$Parameters) | |
$tempFile = [IO.Path]::GetTempFileName() | |
## Store the output of cmd.exe. We also ask cmd.exe to output | |
## the environment table after the batch file completes | |
cmd.exe /c " `"$Path`" $Parameters && set > `"$tempFile`" " |