Skip to content

Instantly share code, notes, and snippets.

@mhudasch
mhudasch / pre-commit-encoding.ps1
Created November 9, 2016 16:45
Git local pre-commit hook script that ensures correct file encoding
function Get-FileEncoding {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string]$Path
)
[byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
$encoding = 'utf8';
if ( $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf )
{ $encoding = 'utf8-with-bom'; }
elseif (($byte[0] -eq 0xfe -and $byte[1] -eq 0xff) <#big endian#>)
@mhudasch
mhudasch / InjectedView.cs
Created July 27, 2017 07:45
Inject a View into another
[DefaultProperty("ViewPropertyBindings")]
[ContentProperty("ViewPropertyBindings")]
internal class InjectedView : FrameworkElement
{
private readonly IKernel kernel;
private FrameworkElement visual;
private ObservableCollection<ViewPropertyBinding> viewPropertyBindings;
@mhudasch
mhudasch / Get-WindowsCredentialManagerPSCredential.ps1
Created January 23, 2018 06:50
Get Credentials from Windows Credentials Manager
#requires -version 5
Set-StrictMode -Version Latest
function Get-WindowsCredentialManagerPSCredential {
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory = $true)]
[Alias("Name")]
[ValidateNotNullOrEmpty()]
[string]$Url
@mhudasch
mhudasch / Get-NugetLicense.ps1
Last active August 5, 2021 14:50
Extract all license infomation of all used nuget packages
$lic = New-Item -ItemType Directory -Name "lic" -Force -ErrorAction "Stop";
$projects = @( Get-Project -All | ? { $_.ProjectName } | % { Get-Package -ProjectName $_.ProjectName } );
$deps = $projects | %{ $_ | Add-Member -MemberType "NoteProperty" -Value "$($_.Id)@$($_.Version)" -Name "Key"; $_ } | Sort -Property "Key" -Unique;
$deps | %{ $pkg = $_; if($null -eq $pkg.LicenseUrl) { Set-Content -Path ($lic.FullName + "\no_license_" + $pkg.Id + ".txt") -Value "NO-LICENCE" } }
$loaded = $deps | %{ $pkg = $_; if($null -ne $pkg.LicenseUrl) { Try { $extMatch = [regex]::Match($pkg.LicenseUrl, '^.*?(\.html?|\.txt)$'); if($extMatch.Success){$ext = $extMatch.Groups[1].Value;} else {$ext = ".html"} $cnt = (New-Object System.Net.WebClient).DownloadString($pkg.LicenseUrl); Write-Host "$($pkg.LicenseUrl) downloaded for $($pkg.Id)."; @{ PKg = $pkg; Content = $cnt; } | Write-Output } Catch [system.exception] { Write-Host "Could not download license for $($pkg.Id) -> '$($pkg.LicenseUrl)'" } } }
$loaded | %{ $pkg = $_["Pkg"];
@mhudasch
mhudasch / Uninstall-ProjectNuGetPackage.ps1
Last active February 14, 2019 09:23
Uninstalles all nuget packages from all projects in a solution
@( Get-Project -All | ? { $_.ProjectName } | % { Get-Package -ProjectName $_.ProjectName } ) | %{ $_ | Add-Member -MemberType "NoteProperty" -Value "$($_.Id)@$($_.Version)" -Name "Key"; $_ } | Sort -Property "Key" -Unique | %{ Uninstall-Package -Id $_.Id -ProjectName $_.ProjectName -Force -RemoveDependencies -ErrorAction Ignore }
@mhudasch
mhudasch / Update-PackagesDirectory.ps1
Created February 17, 2019 15:19
Fixes the nuget restore packages folder when restoring from both servers and directories at the same time.
$packagesPath = (Join-Path -Path $WorkingDirectory -ChildPath "packages");
if (Test-Path -Path $packagesPath) {
Write-Verbose -Message "Fixing packages folder structure...";
$restoredVersionedPackagePaths = @(Get-ChildItem -Path $packagesPath -Directory |
Select-Object -ExpandProperty "FullName" |
ForEach-Object {
$path = $_;
$versionedMatch = [regex]::Match($path, ".*?\\(?<path>packages\\(?<id>.*?)\.(?<version>\d+(?:\.\d+)+))");
if (!$versionedMatch.Success) {
return;
@mhudasch
mhudasch / Microsoft.PowerShell_profile.ps1
Last active May 23, 2025 19:32
The ultimate ps profile for devs
########################################
## Initial data collection inside the host
########################################
$OutputEncoding = [System.Text.Encoding]::Default;
[Console]::OutputEncoding = $OutputEncoding;
$InformationPreference = "Continue";
if ($([System.Environment]::GetCommandLineArgs() -join " ") -inotmatch "(?i)-(?:nologo|noniteractive|noecho)" -and
($([System.Environment]::GetCommandLineArgs() -join " ") -inotmatch "(?i)-command" -or
($([System.Environment]::GetCommandLineArgs() -join " ") -imatch "(?i)-command" -and $([System.Environment]::GetCommandLineArgs() -join " ") -inotmatch ('(?i)\' + $([io.path]::DirectorySeparatorChar) + '(?i)\\(?:.*?(?<!shellIntegration|hr))\.ps1')))) {
@mhudasch
mhudasch / Get_Process_Memory.ps1
Last active March 18, 2019 12:57
Gets the top 5 processes using the most ram. It shows the amount of memory and the overall percentage used.
Get-Process | Group-Object -Property ProcessName | ForEach-Object {
$_ | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $env:ComputerName -Force;
$_ | Add-Member -MemberType NoteProperty -Name "MemoryUsageKB" -Value (($_.Group|Measure-Object WorkingSet -Sum).Sum / 1KB);
$_ | Add-Member -MemberType NoteProperty -Name "MemoryPercentageOnTotal" -Value ((100/(Get-CimInstance -ClassName "CIM_OperatingSystem" -Namespace "root/CIMv2").TotalVisibleMemorySize) * (($_.Group|Measure-Object WorkingSet -Sum).Sum / 1KB));
$_;
} | Sort-Object -Descending -Property "MemoryUsageKB" |
Select-Object -First 5 |
Format-Table -Property "ComputerName","Name", @{n='Mem (KB)';e={'{0:N0}' -f $_.MemoryUsageKB};a='right'}, @{n='% on total';e={'{0:N2}%' -f $_.MemoryPercentageOnTotal};a='right'}
@mhudasch
mhudasch / .gitconfig
Last active August 27, 2021 12:58
meine gitconfig
[user]
name = Martin Hudasch
email = [email protected]
[push]
default = simple
[alias]
list-aliases = !git config --list | grep ^alias\\. | cut -c 7- | grep -Ei --color \"$1\" "#"
aliases = list-aliases
la = list-aliases
st = status
@mhudasch
mhudasch / settings.json
Created April 22, 2020 09:04
My VSCode Settings
{
"editor.insertSpaces": true,
"editor.useTabStops": false,
"editor.detectIndentation": false,
"editor.renderWhitespace": "all",
"editor.tabSize": 2,
"editor.roundedSelection": true,
"editor.trimAutoWhitespace": true,
"editor.renderIndentGuides": true,
"editor.formatOnSave": true,