Skip to content

Instantly share code, notes, and snippets.

View matsest's full-sized avatar

Mats Estensen matsest

View GitHub Profile
@matsest
matsest / go-update.sh
Created March 30, 2024 14:52
Update golang
#!/bin/bash
# Check privileges
if [ "$(id -u)" -ne 0 ]
then echo Please run this script as root or using sudo!
exit
fi
# Print current version
export PATH=$PATH:/usr/local/go/bin
@matsest
matsest / clean-snaps.sh
Created January 31, 2024 08:36
Clean old Snap revisions
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@matsest
matsest / networkranges.ps1
Last active June 27, 2023 14:54
Sorting IP address spaces with PowerShell
# Define ranges
$NetworkRanges = @(
'10.11.0.0/24'
'10.11.1.0/24'
'10.11.12.0/24'
'10.11.24.0/24'
'10.11.2.0/24'
)
# Bad - does not sort according to address spaces, only alphanumerical :(
@matsest
matsest / .bashrc
Last active May 31, 2023 14:14
VimEscapeEverything
## Add this to your .bash_rc / .zshrc
# Alias for vim-style exit in Bash/Zsh
alias :q=exit
@matsest
matsest / asg-in-nsg-rules.kql
Last active January 31, 2024 11:10
Various Azure Resource Graph queries
resources
| where type == "microsoft.network/networksecuritygroups"
| extend securityRules = properties.securityRules
| mv-expand securityRules
| where securityRules.properties.destinationApplicationSecurityGroups != '' or securityRules.properties.sourceApplicationSecurityGroups != ''
| mv-expand srcAsgs = securityRules.properties.sourceApplicationSecurityGroups
| mv-expand dstAsgs = securityRules.properties.destinationApplicationSecurityGroups
| extend srcAsgNames = split(srcAsgs.id, "/")[-1]
| extend dstAsgNames = split(dstAsgs.id, "/")[-1]
| mv-expand subnet = properties.subnets
@matsest
matsest / main.bicep
Last active August 17, 2022 06:35
Management Group Diagnostic Settings
targetScope = 'managementGroup'
param name string
param displayName string = name
param parentName string = ''
param workspaceResourceId string = ''
resource managementGroup 'Microsoft.Management/managementGroups@2021-04-01' = {
name: name
scope: tenant()
@matsest
matsest / servicetags.ps1
Created February 16, 2022 11:19
azure network tags
$serviceTagCollections = Get-AzNetworkServiceTag -Location "Norway East"
$serviceTags = $serviceTagCollections | Where-Object Name -eq "Public" | Select-Object -ExpandProperty Values
$regionalServices = $serviceTags | ? { $_.Properties.Region -like "norway*" }
$nonRegionalServices = $serviceTags | ? { -not $_.Properties.Region }
@matsest
matsest / check-expired-apps.ps1
Created January 7, 2022 14:24
az-service-principal
#requires -modules @{ ModuleName="Az.Resources"; ModuleVersion="5.0.0" }
[CmdletBinding()]
param(
[Parameter(HelpMessage = 'Will output credentials if withing this number of days, use 0 to report only expired and valid as of today')]
$ExpiresInDays = 90
)
Write-Host 'Gathering necessary information...'
$applications = Get-AzADApplication
Get-Module -Name az.* -ListAvailable |
Where-Object -Property Name -ne ‘Az.’ |
ForEach-Object {
$currentVersion = [Version] $_.Version
$newVersion = [Version] (Find-Module -Name $_.Name).Version
if ($newVersion -gt $currentVersion) {
Write-Host -Object "Updating $_ Module from $currentVersion to $newVersion"
Update-Module -Name $_.Name -RequiredVersion $newVersion -Force
Uninstall-Module -Name $_.Name -RequiredVersion $currentVersion -Force
}
@matsest
matsest / stopZoomScroll.ahk
Created March 23, 2020 12:26
AutoHotKey script to stop annoying behaviour on laptops where ctrl+scroll on touchpad leads to unintentional zooms
#MaxHotkeysPerInterval 500
^WheelDown::return
^WheelUp::return