Instantly share code, notes, and snippets.

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`" "
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,
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
}
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)
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);
}
else
{
baseRegistryHklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
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){
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"
}
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 major.minor.build (e.g. "6.7.35698")
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
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")]
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"
throw
}
$testPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WebApplication1.Tests"