Skip to content

Instantly share code, notes, and snippets.

@mhudasch
mhudasch / myprompt.json
Created September 24, 2023 12:49
oh-my-posh Settings
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#C50F1F",
"foreground": "#FFFFFF",
"style": "powerline",
@mhudasch
mhudasch / settings.json
Created September 24, 2023 12:44
Windows Terminal Settings
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "copy",
"singleLine": false
@mhudasch
mhudasch / Get-RandomString.ps1
Last active March 8, 2022 07:13
Creates Random strings like passwords
function Get-RandomString {
param(
[Parameter()][ValidateRange(8, 4000)]
[int]$MaxLength = 16,
[Parameter()][ValidateRange(1,1000)]
[int]$MinCountLowerCaseLetters=1,
[Parameter()][ValidateRange(1,1000)]
[int]$MinCountUpperCaseLetters=1,
[Parameter()][ValidateRange(1,1000)]
[int]$MinCountDigits=1,
@mhudasch
mhudasch / Export-TrustedCertificate.ps1
Last active February 9, 2022 12:27
Exports trusted root CAs to programs that do not use the Windows Certificate Store
#Requires -Version 5
#Requires -PSEdition Desktop
function Get-RootCAFromUrl {
[CmdletBinding()]
param(
# The uri of the website with the server certificate
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[uri]
@mhudasch
mhudasch / EFCoreFix.cs
Last active July 13, 2020 09:06
Fix for the sqlite composite primary key (compound key) auto incrementation issue.
//...
// in the DbContext -> protected override void OnModelCreating(ModelBuilder modelBuilder)
// orverride the property which is the key that should be incremented automatically
// - or do it for all the keys that need that
if (this.Database.IsSqlite())
{
// generally fix the sqlite composite primary key auto increment issue
// see https://github.com/dotnet/efcore/issues/15497
@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,
@mhudasch
mhudasch / .gitconfig
Last active August 27, 2021 12:58
meine gitconfig
[user]
name = Martin Hudasch
email = martin.hudasch@live.de
[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 / 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 / Microsoft.PowerShell_profile.ps1
Last active March 15, 2024 08:08
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 / 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;