Skip to content

Instantly share code, notes, and snippets.

Benoît Patra bpatra

Block or report user

Report or block bpatra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
bpatra / gist:d10ecab36f75f46ae62913051380899e
Created Dec 13, 2016
Powershell functions to load VS2015 VCVARS in Powershell (you may want to add it to you powsershell profile)
View gist:d10ecab36f75f46ae62913051380899e
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`" "
bpatra / gist:8b3cf6a1568a9ae580c2
Last active Jan 28, 2016
Comments on validate issuer
View gist:8b3cf6a1568a9ae580c2
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,
bpatra / restart_audioHDMIDrivers
Created Dec 21, 2013
PoSh script to restart drivers for HDMI sound
View restart_audioHDMIDrivers
$devcon = "C:\Program Files (x86)\Windows Kits\8.1\Tools\x64\devcon.exe"
$audioID = "@HDAUDIO\FUNC_01&VEN_8086&DEV_2807&SUBSYS_80860101&REV_1000\4&36161A1D&0&0001"
$displayID = "@PCI\VEN_8086&DEV_0A16&SUBSYS_130D1043&REV_09\3&11583659&0&10"
. $devcon enable $audioID
. $devcon enable $displayID
. $devcon restart $audioID
. $devcon restart $displayId
bpatra / BasicUnion
Last active Dec 26, 2015
The basic Union method in ExcelInterop
View BasicUnion
//builds the union range form the indices
private static Range Union(IEnumerable<int> rows)
Range range = null;
foreach (int row in rows)
var currentLine = ExcelAddIn.ActiveSheet.Range["A" + row + ":" + "C" + row];
range = range == null ? currentLine : ExcelAddIn.Application.Union(range, currentLine);
return range;
bpatra / ExportAliasWitExeInPath
Last active Dec 20, 2015
Part of a PoSh profile to import/export all executables located under PATH. Export-AliasWithEXEInPATH is a function that exports alias with all .exe located under PATH environment variable. The alias exported file is named alias.txt and is exported next to the $PROFILE .ps1 file. These aliases are imported just before loading module PowerTab.
View ExportAliasWitExeInPath
$aliasesPath = Join-Path -Path ([System.IO.Path]::GetDirectoryName($PROFILE)) -ChildPath "alias.txt"
function Export-AliasWithEXEInPATH
$aliasDict = @{}
$existingAlias = Get-Alias | ForEach-Object {$_.Name}
foreach($aliasName in $existingAlias)
bpatra / startfile
Created Aug 5, 2013
startfile for conemu
View startfile
/BufferHeight 1000 powershell
bpatra / gist:6098656
Last active Dec 20, 2015
F#ception. test execution with factorial
View gist:6098656
type FsCeptionTests () =
member this.WithFactorial () =
let myTest = "module dafuq
let rec factorial n =
match n with
| 0 -> 1
| 1 -> 1
bpatra / gist:6098637
Created Jul 28, 2013
F#-ception. ExecutePsScript
View gist:6098637
let ExecPsScript<'T> script =
let runspaceConfiguration = RunspaceConfiguration.Create()
let runspaceAssemblies = runspaceConfiguration.Assemblies
let assembliesConfiguration =
|> (fun asm -> new AssemblyConfigurationEntry(asm.FullName, asm.Location))
assembliesConfiguration |> runspaceAssemblies.Append
|> (fun asm -> asm.FileName)
|> (fun path -> new TypeConfigurationEntry(path))
bpatra / gist:6098579
Last active Dec 20, 2015
F#-ception, testing Fs2Ps with a very simple example
View gist:6098579
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")
bpatra / gist:6098589
Created Jul 28, 2013
Powershell script in simpleExample.ps1 generated by FsToPs
View gist:6098589
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
You can’t perform that action at this time.