Skip to content

Instantly share code, notes, and snippets.

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 / Nice gitlog
Created Dec 4, 2014
A nice Powershell gitlog to view your commits
View Nice gitlog
function GitLog
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
bpatra / YAML extractor
Created Aug 24, 2014
Powershell script for extracting YAMLS out of Jekyll files
View YAML extractor
#Script for extractingn YAML of .html files.
#The extracted content is put in a directory YAMLS <websiteroot>/ignored/YAMLS
if(-Not (Test-Path (Join-Path $PSScriptRoot -ChildPath "ignored"))){
throw "It is assumed that a directory ignored exists"
function ContainsYAML([string] $htmlFile){
$lines = Get-Content $htmlFile
$lineCount = $lines.Length - 1
$indices = (0 .. $lineCount)
bpatra / gist:bd641ee939f2c70ed3d9
Last active Aug 29, 2015
Choosing the proper registry
View gist:bd641ee939f2c70ed3d9
RegistryKey baseRegistryHklm;
RegistryKey baseRegistryHkcu;
if (Environment.Is64BitOperatingSystem) //Use OS not process...
baseRegistryHklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
baseRegistryHkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
baseRegistryHklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
bpatra / functionPatchAssemblyInfo.ps1
Created Jul 8, 2014
Details of the functions used in the PatchAssemblyInfo PSake task
View functionPatchAssemblyInfo.ps1
function GetRevisionNumber {
$major = "1"
$minor = "0"
#we use the environment variable BUILD_NUMBER provided by teamcity, use -1 is not found to test locally the process
$patch= if ([string]::IsNullOrEmpty($env:BUILD_NUMBER)) { "-1" } else { $env:BUILD_NUMBER }
$major + "." + $minor + "." + $patch
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
bpatra / bootstrap.ps1
Last active Aug 29, 2015
This script loads all file and defines the high level targets
View bootstrap.ps1
#load all targets
Get-ChildItem (Join-Path $PSScriptRoot -ChildPath "./targets") | ForEach-Object{ & $_.FullName }
Task Example -Depends PatchAssemblyInfo, RenameMSI {
Write-Host "Example target executed"
bpatra / PatchAssemblyInfo.ps1
Last active Aug 29, 2015
the detail of the PatchAssemblyInfo task
View PatchAssemblyInfo.ps1
Task PatchAssemblyInfo{
function GetAssemblyVersion {
#skip the details for now -> returns the version major.minor (e.g. "6.7")
function GetAssemblyFileVersion {
#skip the details for now -> returns the long version (e.g. "6.7.35698")
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
bpatra / AssemblyInfo.cs
Last active Aug 29, 2015
A sample assembly info file
View AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("armenAnalytics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("armenAnalytics")]
[assembly: AssemblyCopyright("Copyright © 2014")]
bpatra / chutzPahTests.ps1
Created May 28, 2014
Sample powershell script (V4.0) for executing javascript tests with chutzpah runner.
View chutzPahTests.ps1
$chutzpahPath = (Join-Path -Path $PSScriptRoot -ChildPath "Chutzpah.3.2.1\chutzpah.console.exe").ToString()
If(-not (Test-Path($chutzpahPath)))
Write-Error "Cannot find chutzpath"
$testPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WebApplication1.Tests"
You can’t perform that action at this time.