Skip to content

Instantly share code, notes, and snippets.

@bpatra
bpatra / gist:bd641ee939f2c70ed3d9
Last active August 29, 2015 14:04
Choosing the proper registry
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);
@bpatra
bpatra / YAML extractor
Created August 24, 2014 13:18
Powershell script for extracting YAMLS out of Jekyll files
#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
bpatra / Nice gitlog
Created December 4, 2014 09:59
A nice Powershell gitlog to view your commits
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
bpatra / gist:8b3cf6a1568a9ae580c2
Last active January 28, 2016 10:58
Comments on validate issuer
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
bpatra / gist:d10ecab36f75f46ae62913051380899e
Created December 13, 2016 13:52
Powershell functions to load VS2015 VCVARS in Powershell (you may want to add it to you powsershell profile)
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
bpatra / resize.ps1
Last active December 5, 2020 20:15
Resize Powershell
Param ( [Parameter(Mandatory=$True)] [ValidateNotNull()] $imageSource,
[Parameter(Mandatory=$True)] [ValidateNotNull()] $imageTarget,
[Parameter(Mandatory=$true)][ValidateNotNull()] $quality )
if (!(Test-Path $imageSource)){throw( "Cannot find the source image")}
if(!([System.IO.Path]::IsPathRooted($imageSource))){throw("please enter a full path for your source path")}
if(!([System.IO.Path]::IsPathRooted($imageTarget))){throw("please enter a full path for your target path";)}
if ($quality -lt 0 -or $quality -gt 100){throw( "quality must be between 0 and 100.")}
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
public interface IPlayerSearchViewModel
{
string SearchPlayerText { get; set; }
ICollectionView DisplayedPlayers { get; }
}
public class PlayerSearchViewModel : IPlayerSearchViewModel
{
private readonly ICollectionView _view;
private string _textsearch;
public PlayerSearchViewModel(IPlayerProvider playerProvider)
{
_view = CollectionViewSource.GetDefaultView(playerProvider.GetAllWorldCupPlayer());
_view.Filter += (object item) =>
{
public interface ICollectionView<T> : IEnumerable<T>, ICollectionView
{
IEnumerable<T> SourceCollectionGeneric { get; }
//Add here your "generic methods" e.g.
//e.g. Predicate<T> Filter {get;set;} etc.
}
public class MyCollectionViewGeneric<T> : ICollectionView<T>
{
private readonly ICollectionView _collectionView;
public MyCollectionViewGeneric(ICollectionView generic)
{
_collectionView = generic;
}
private class MyEnumerator : IEnumerator<T>