Skip to content

Instantly share code, notes, and snippets.

View audunsolemdal's full-sized avatar
In the clouds

Audun Solemdal audunsolemdal

In the clouds
View GitHub Profile
@audunsolemdal
audunsolemdal / terraform-module-mover.sh
Last active June 3, 2024 14:04
Terraform - move module contents to root module or to another nested module
#!/bin/bash
# Generates terraform "moved" blocks for files based on terraform state
export OLD_MODULE="old_module_name"
export NEW_MODULE="" #LEAVE EMPTY to move to root module or enter "module.new_module." if you want to move to another module
terraform state list |
grep module.${OLD_MODULE} | cut -d. -f 3- | sed 's/\"/\\\"/g' |
xargs -I {} sh -c 'echo "moved {" && echo " from = module.${OLD_MODULE}.{}" && echo " to = ${NEW_MODULE}{}" && echo "}"' | sed 's/\]/\"]/g' | sed 's/\[/\["/g' | tr -d '\r' > moved-blocks.tf
@axelheer
axelheer / ConvertTo-CentralPackageManagement.ps1
Last active September 4, 2024 08:21
Generates a `Directory.Packages.props` based on all your project files
function ConvertTo-CentralPackageManagement() {
Write-Host 'Searching for package references'
$packages = @{}
$conditionalPackages = @{}
foreach ($csproj in (Get-ChildItem -Include *.csproj, *.props -Recurse)) {
$root = [xml]($csproj | Get-Content -Raw)
foreach ($itemGroup in $root.Project.ItemGroup) {
foreach ($packageReference in $itemGroup.PackageReference) {
if ($packageReference.Include -and $packageReference.Version) {
@SQLDBAWithABeard
SQLDBAWithABeard / powershell.json
Last active October 8, 2021 18:09
powershell vscode snippets
{
/*
These are PowerShell snippets which you can use in Visual Studio Code
To use them click File --> Preferences --> User Snippets and type PowerShell
or edit $env:\appdata\code\user\snippets\powershell.json
In general and in order I converted exisitng snippets like this
Replace `$ with $$
Replace \ with \\
Replace " with \"
\r for new line
@SQLDBAWithABeard
SQLDBAWithABeard / prompt.ps1
Last active March 21, 2024 07:16
new improved colourful prompt
######## POSH-GIT
# with props to https://bradwilson.io/blog/prompt/powershell
#
#
# Now for this to work most beautifully - you will need to have the latest posh-git module
#
# You will also need the MesloLGM Nerd Font Mono font
# from here https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Meslo/M/Regular/complete/Meslo%20LG%20M%20Regular%20Nerd%20Font%20Complete.ttf
# if you are super nerdy
# or
@ilbunilcho
ilbunilcho / How to remove Windows paths from WSL path.md
Created November 1, 2018 16:41
How to remove Windows paths from WSL path

after Build 17093

  • can override settings by edit "/etc/wsl.conf"
  • normally this file is not exists at first
$ sudo vi /etc/wsl.conf

[interop]
appendWindowsPath = false

Credit: Mark Kraus
Website: https://get-powershellblog.blogspot.com

Collection Type Guidence

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.
@psignoret
psignoret / Get-AzureADPSPermissions.ps1
Last active November 12, 2024 19:40
Script to list all delegated permissions and application permissions in Microsoft Entra ID
# THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF
# FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
#Requires -Modules @{ ModuleName="Microsoft.Graph.Authentication" ; ModuleVersion="2.15.0" }
#Requires -Modules @{ ModuleName="Microsoft.Graph.DirectoryObjects"; ModuleVersion="2.15.0" }
#Requires -Modules @{ ModuleName="Microsoft.Graph.Identity.SignIns"; ModuleVersion="2.15.0" }
#Requires -Modules @{ ModuleName="Microsoft.Graph.Applications" ; ModuleVersion="2.15.0" }
#Requires -Modules @{ ModuleName="Microsoft.Graph.Users" ; ModuleVersion="2.15.0" }
<#
@sacreman
sacreman / prometheus.yml
Last active June 23, 2022 09:06
Prometheus configuration to scrape Kubernetes outside the cluster
# Prometheus configuration to scrape Kubernetes outside the cluster
# Change master_ip and api_password to match your master server address and admin password
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
# metrics for the prometheus server
- job_name: 'prometheus'
@dzimchuk
dzimchuk / gist:1e45174d3a63705b9171
Last active February 2, 2022 16:41
PowerShell script to copy Azure Table from one account to another
param (
[string]
$sourceConnectionString = $(throw "-sourceConnectionString is required."),
[string]
$sourceTableName = $(throw "-sourceConnectionString is required."),
[string]
$targetConnectionString = $(throw "-targetConnectionString is required."),
[string]
$targetTableName = $(throw "-targetTableName is required.")
)