From 4904e0a41f210ab0757410aefab5897101863280 Mon Sep 17 00:00:00 2001 From: jantari Date: Sun, 9 Oct 2022 16:08:16 +0200 Subject: [PATCH 01/41] add good-practice example of not using += with arrays --- good-practices/add-to-array.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 good-practices/add-to-array.ps1 diff --git a/good-practices/add-to-array.ps1 b/good-practices/add-to-array.ps1 new file mode 100644 index 0000000..00595cf --- /dev/null +++ b/good-practices/add-to-array.ps1 @@ -0,0 +1,17 @@ +# Adding to an array with += is much slower: + +$list = @() +Measure-Command { + foreach ($number in $(1..10000)) { + $list += $number + } +} + +# than capturing the output of the loop directly: + +Measure-Command { + $list = foreach ($number in $(1..10000)) { + $number + } +} + From 7fa8d19576f498516e09bcfc156f7828270553b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 30 Oct 2022 20:35:14 +0100 Subject: [PATCH 02/41] how to return arrays from functions to not cause performance issues --- good-practices/return.ps1 | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 good-practices/return.ps1 diff --git a/good-practices/return.ps1 b/good-practices/return.ps1 new file mode 100644 index 0000000..aa812fb --- /dev/null +++ b/good-practices/return.ps1 @@ -0,0 +1,64 @@ +Clear-Host +$tmpFile = 'd:\temp\tmp.mp4' + +function Get-Obj { + [byte[]]$payload = [System.IO.File]::ReadAllBytes($tmpFile) + $payload +} + +function Get-Wrapped { + [byte[]]$payload = [System.IO.File]::ReadAllBytes($tmpFile) + @{ wrap = $payload } +} + +function Get-Operator { + [byte[]]$payload = [System.IO.File]::ReadAllBytes($tmpFile) + ,$payload +} + +function Get-WriteOutput { + [byte[]]$payload = [System.IO.File]::ReadAllBytes($tmpFile) + Write-Output $payload -NoEnumerate +} + +Measure-Command { + [byte[]]$out1 = Get-Obj + Write-Host "Size: $($out1.Length)" +} + +Measure-Command { + $out2 = Get-Wrapped + Write-Host "Size: $($out2.wrap.Length)" +} + +Measure-Command { + $out3 = Get-Operator + Write-Host "Size: $($out3.Length)" +} + +Measure-Command { + $out4 = Get-WriteOutput + Write-Host "Size: $($out4.Length)" +} + +# OUTPUT for 6.5 MB file + +##### Get-Obj ##### +# Size: 6 439 243 +# TotalSeconds : 2.4369009 +# TotalMilliseconds : 2436.9009 + +##### Get-Wrapped ##### +# Size: 6 439 243 +# TotalSeconds : 0.0087145 +# TotalMilliseconds : 8.7145 + +##### Get-Operator ##### +# Size: 6 439 243 +# TotalSeconds : 0.025268 +# TotalMilliseconds : 25.268 + +##### Get-WriteOutput ##### +# Size: 6 439 243 +# TotalSeconds : 0.0205171 +# TotalMilliseconds : 20.5171 \ No newline at end of file From 26c6f94f629093492045d650d6c1cb740582a888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 1 Nov 2022 08:04:10 +0100 Subject: [PATCH 03/41] register Windows schedules tasks running in the background --- tasks/register-scheduled-task.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tasks/register-scheduled-task.ps1 diff --git a/tasks/register-scheduled-task.ps1 b/tasks/register-scheduled-task.ps1 new file mode 100644 index 0000000..8c4db3d --- /dev/null +++ b/tasks/register-scheduled-task.ps1 @@ -0,0 +1,21 @@ +$name = [guid]::NewGuid() +$trigger = New-ScheduledTaskTrigger -Once -At 9am +$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest + +# inline script +$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -command "& { Write-Host 1 }"' +# file script +$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoLogo -WindowStyle hidden -file C:\script.ps1' + +$task = Register-ScheduledTask ` + -TaskName $name ` + -Description "Background task" ` + -Trigger $trigger ` + -Action $action ` + -TaskPath '\Alan\jobs' ` + -Principal $principal + +Write-Host "Created: $($task.TaskName) under $($task.TaskPath)" + +# display tasks in folder +Get-ScheduledTask -TaskPath "\Alan\*" \ No newline at end of file From 4c488f2f0ff9f00412840b71006327cb15d8a8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 1 Oct 2023 23:09:33 +0200 Subject: [PATCH 04/41] Added choco update script for AFK case (run and forget) --- choco/choco upgrade update all and hibernate.bat | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 choco/choco upgrade update all and hibernate.bat diff --git a/choco/choco upgrade update all and hibernate.bat b/choco/choco upgrade update all and hibernate.bat new file mode 100644 index 0000000..815444f --- /dev/null +++ b/choco/choco upgrade update all and hibernate.bat @@ -0,0 +1,3 @@ +choco upgrade all -y +%windir%\system32\rundll32.exe powrprof.dll,SetSuspendState +pause \ No newline at end of file From 9bba5196a6799a5e44f2b89b9e97afbc05e0cebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Mon, 2 Oct 2023 12:25:57 +0200 Subject: [PATCH 05/41] Added "Hacker" theme for workspace settings --- .vscode/settings.json | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d2ab49a..362f367 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,14 @@ { - "editor.fontSize": 18, - "workbench.colorTheme": "PowerShell ISE", - "workbench.colorCustomizations": { - "editor.selectionBackground": "#99c8ef96", - "editor.selectionHighlightBackground": "#99C9EF", - "editor.lineHighlightBackground": "#ffffff" - }, - "files.defaultLanguage": "powershell", - "files.associations": { - "*.wsb": "xml" - } + "editor.fontSize": 18, + "workbench.colorTheme": "Monokai Charcoal Full Dark", + "workbench.colorCustomizations": { + "editor.lineHighlightBackground": "#202020", + "editor.selectionHighlightBackground": "#141414", + "editor.selectionHighlightBorder": "#b3ff00", + "editor.background": "#0A0A0A" + }, + "files.defaultLanguage": "powershell", + "files.associations": { + "*.wsb": "xml" + } } \ No newline at end of file From 981b2ddca8c89d9eaad582dc6deb2251e1d9b23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 3 Oct 2023 21:12:55 +0200 Subject: [PATCH 06/41] Added reflection examples --- development/ps/reflection.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 development/ps/reflection.ps1 diff --git a/development/ps/reflection.ps1 b/development/ps/reflection.ps1 new file mode 100644 index 0000000..02b3afe --- /dev/null +++ b/development/ps/reflection.ps1 @@ -0,0 +1,25 @@ +# constructor +$constructorInfo = [System.IO.FileInfo].GetConstructor([string].AsType()) +$constructorInfo = [System.IO.FileInfo].GetConstructor("public,instance", $types) +$constructorInfo.Invoke('C:\Windows') + +# private field +$obj = [System.IO.FileInfo]::new('C:\Windows') +$field = [System.IO.FileInfo].GetField("_name", "nonpublic,instance") +# longer version +$field = [System.IO.FileInfo].GetField("_name", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance) +$field.GetValue($obj) + +# private method - static +$obj = $null +$privMethod = [System.DateTime].GetMember("DateToTicks", "nonpublic,static") +$privMethod.Invoke($obj, @(2023, 10, 10)) + +# private method - instance +$obj = [System.DateTime]::Now +$privMethod = [System.DateTime].GetMember("GetDatePart", "nonpublic,instance") +$privMethod.Invoke($obj, @(0)) + +# private method - args requirements +$privMethod = [System.DateTime].GetMethod("DateToTicks", "nonpublic,static", $null, @([int], [int], [int]), @()) +$privMethod.Invoke($obj, @(2023, 10, 10)) \ No newline at end of file From 0488524e4db7fc95ffcd32b9e00d1658beab10bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Thu, 18 Jan 2024 19:32:04 +0100 Subject: [PATCH 07/41] Added setup-ssh-for-git.ps1 --- git/setup-ssh-for-git.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 git/setup-ssh-for-git.ps1 diff --git a/git/setup-ssh-for-git.ps1 b/git/setup-ssh-for-git.ps1 new file mode 100644 index 0000000..a4c5d68 --- /dev/null +++ b/git/setup-ssh-for-git.ps1 @@ -0,0 +1,30 @@ +# Prerequisites - you need to get SSH key supported by your git hosting service. +# deploy it into: c:\id_rsa + +# install choco +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +# install dependencies +choco install git -y + +# deploy SSH key into keys store +$userName = [Environment]::UserName +Write-Host "Username: $userName" -ForegroundColor Green +Get-Item c:\id_rsa | Copy-Item -Destination "C:\Users\$userName\.ssh\id_rsa" + +# enable ssh service +Get-Service -Name ssh-agent | Set-Service -StartupType Manual +Start-Service ssh-agent + +# register ssh key +ssh-add "C:\Users\$userName\.ssh\id_rsa" + +# register known_hosts +ssh-keyscan bitbucket.org >> "C:\Users\$userName\.ssh\known_hosts" +ssh-keyscan github.com >> "C:\Users\$userName\.ssh\known_hosts" +ssh-keyscan vs-ssh.visualstudio.com >> "C:\Users\$userName\.ssh\known_hosts" + +# test connection to git repositories +ssh -T ssh://alan-null@vs-ssh.visualstudio.com +ssh -T git@bitbucket.org +ssh -T git@github.com \ No newline at end of file From 61759e991efa774e9c6fa9264d04145dcde378b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Wed, 24 Jan 2024 19:25:12 +0100 Subject: [PATCH 08/41] Miscellaneous stuff --- .gitignore | 1 + .test/dist/.gitkeep | 0 .vscode/settings.json | 2 +- excel/convert-xlsx-to-csv.ps1 | 2 +- system-maintenance/create-file-snapshot.ps1 | 3 +++ 5 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .test/dist/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..45754bd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.test/dist/ diff --git a/.test/dist/.gitkeep b/.test/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/settings.json b/.vscode/settings.json index 362f367..34a4d5e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.fontSize": 18, - "workbench.colorTheme": "Monokai Charcoal Full Dark", + "workbench.colorTheme": "Default Dark Modern", "workbench.colorCustomizations": { "editor.lineHighlightBackground": "#202020", "editor.selectionHighlightBackground": "#141414", diff --git a/excel/convert-xlsx-to-csv.ps1 b/excel/convert-xlsx-to-csv.ps1 index 2da3374..ec00332 100644 --- a/excel/convert-xlsx-to-csv.ps1 +++ b/excel/convert-xlsx-to-csv.ps1 @@ -50,6 +50,6 @@ $wsEmpty.Activate() 1..2 | % { $wsEmpty.Rows(1).Delete() | Out-Null } # save file as csv -$wsEmpty.SaveAs("$scriptPath\..\.test\excel.csv", 6) +$wsEmpty.SaveAs("$scriptPath\..\.test\dist\excel.csv", 6) # close excel application $Excel.Quit() \ No newline at end of file diff --git a/system-maintenance/create-file-snapshot.ps1 b/system-maintenance/create-file-snapshot.ps1 index c809a0b..baeb5f4 100644 --- a/system-maintenance/create-file-snapshot.ps1 +++ b/system-maintenance/create-file-snapshot.ps1 @@ -20,6 +20,9 @@ try { git commit -m "$date" } } +catch{ + Write-Error $_.Exception +} finally { Set-Location $current } From 8f954acab4423ca0ae80708b46db6d35c542d6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 5 May 2024 08:59:25 +0200 Subject: [PATCH 09/41] Added rename-files-lastwritetime append date as a prefix for file name --- filesystem/rename-files-lastwritetime.ps1 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 filesystem/rename-files-lastwritetime.ps1 diff --git a/filesystem/rename-files-lastwritetime.ps1 b/filesystem/rename-files-lastwritetime.ps1 new file mode 100644 index 0000000..68c3790 --- /dev/null +++ b/filesystem/rename-files-lastwritetime.ps1 @@ -0,0 +1,5 @@ +Get-ChildItem "D:\___to backup\" | % { + $date = $_.LastWriteTime.ToString("yyyy-MM-dd") + $name = $_.Name + $_ | Rename-Item -NewName "$date-$name" +} \ No newline at end of file From 9cad3d7d1afb128fd75a54a6e176b98ff0503984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Wed, 6 Nov 2024 18:27:53 +0100 Subject: [PATCH 10/41] Added split kml.ps1 --- .vscode/settings.json | 1 + file-processing/split kml.ps1 | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 file-processing/split kml.ps1 diff --git a/.vscode/settings.json b/.vscode/settings.json index 34a4d5e..1a5e063 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + // "editor.fontFamily": "Cascadia Code, jetbrains mono, 'Courier New', monospace", // fallback fonts "editor.fontSize": 18, "workbench.colorTheme": "Default Dark Modern", "workbench.colorCustomizations": { diff --git a/file-processing/split kml.ps1 b/file-processing/split kml.ps1 new file mode 100644 index 0000000..512ea54 --- /dev/null +++ b/file-processing/split kml.ps1 @@ -0,0 +1,27 @@ +$kmlPath = 'C:\big.kml' +$max = 240 +$partsFolder = "$PSScriptRoot\parts" + +[xml]$doc = Get-Content -Path $kmlPath +mkdir $partsFolder -ErrorAction SilentlyContinue | Out-Null +$i = 1 +do { + [xml]$clone = $doc.Clone() + $clone.ChildNodes[0].Encoding = $null + + # remove everything except max number count (i.e 240, 480, 720) + $clone.kml.Document.Folder.Placemark | Select-Object -Skip ($max * $i) | % { + $clone.kml.Document.Folder.RemoveChild($_) | Out-Null + } + + # buffering - selecting last max number count + while ($clone.kml.Document.Folder.Placemark.Count -gt $max) { + $clone.kml.Document.Folder.Placemark | Select-Object -First 1 | % { + $clone.kml.Document.Folder.RemoveChild($_) | Out-Null + } + } + + $clone.Save("$partsFolder\_part2_$($i).kml") + $i++ +} +while ($max * $i -le $doc.kml.Document.Folder.Placemark.Count) \ No newline at end of file From d19fffc0cc321e5fea3f9cfcc7e7a0bf6b4463b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Thu, 7 Nov 2024 23:22:38 +0100 Subject: [PATCH 11/41] Added find-large-files.sh used to scan git gistory and find lard files. Results sorted by size --- git/find-large-files.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/find-large-files.sh diff --git a/git/find-large-files.sh b/git/find-large-files.sh new file mode 100644 index 0000000..347b7ca --- /dev/null +++ b/git/find-large-files.sh @@ -0,0 +1,21 @@ +git rev-list --objects --all | + git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | + sed -n 's/^blob //p' | + awk '$2 >= 2^20' | + sort --numeric-sort --key=2 | + cut -c 1-12,41- | + $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest + +# example output +# 22c19f287836 1.0MiB images/posts/1.gif +# 0e15a02b835a 1.2MiB images/posts/2.gif +# f48d3086bf1d 1.5MiB images/posts/3.gif +# eecf2e1d46a7 1.6MiB images/posts/4.gif +# a267f286e7f2 1.7MiB images/posts/5.gif +# 225cba92676b 3.4MiB images/posts/6.gif + +# to find commits with SHA use +# git log --raw --all --find-object=225cba92676b + +# to find all files with given extension +# git log --all --full-history -- *.gif \ No newline at end of file From 6f265d5d45abf5f5914eb4aaa50fe9a32bf53f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sat, 9 Nov 2024 23:35:41 +0100 Subject: [PATCH 12/41] good-practices powershell --- good-practices/foreach-object.ps1 | 9 +++++++++ good-practices/where-object.ps1 | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 good-practices/foreach-object.ps1 create mode 100644 good-practices/where-object.ps1 diff --git a/good-practices/foreach-object.ps1 b/good-practices/foreach-object.ps1 new file mode 100644 index 0000000..c07fe8d --- /dev/null +++ b/good-practices/foreach-object.ps1 @@ -0,0 +1,9 @@ +# BAD +@(1, 2, 3) | Foreach-Object { + # do stuff +} + +# GOOD - 2x faster +foreach ($i in @(1, 2, 3)) { + # do stuff +} \ No newline at end of file diff --git a/good-practices/where-object.ps1 b/good-practices/where-object.ps1 new file mode 100644 index 0000000..4a6dd44 --- /dev/null +++ b/good-practices/where-object.ps1 @@ -0,0 +1,11 @@ +# BAD +$array = @(1, 2, 3, 1, 3, 4) | Where-Object { $_ -eq 1 } + +# GOOD - x17 faster +$array = @( + foreach ($i in @(1, 2, 3, 1, 3, 4)) { + if ($i -eq 1) { + $i + } + } +) \ No newline at end of file From 01dacc553784a3b9a3a3e8d8a2e296b01f5f4fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Thu, 14 Nov 2024 22:12:21 +0100 Subject: [PATCH 13/41] ui interaction with powershell --- windows/ui interaction with powershell.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 windows/ui interaction with powershell.ps1 diff --git a/windows/ui interaction with powershell.ps1 b/windows/ui interaction with powershell.ps1 new file mode 100644 index 0000000..2ead253 --- /dev/null +++ b/windows/ui interaction with powershell.ps1 @@ -0,0 +1,13 @@ +# Focus Assist Off +Add-Type -AssemblyName System.Windows.Forms +[System.Windows.Forms.SendKeys]::SendWait("(^{ESC})") +Start-Sleep -Milliseconds 500 +[System.Windows.Forms.SendKeys]::SendWait("(Focus Assist)") +Start-Sleep -Milliseconds 200 +[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") +Start-Sleep -Milliseconds 700 +[System.Windows.Forms.SendKeys]::SendWait("{TAB}{TAB} ") +Start-Sleep -Milliseconds 500 +[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") +Start-Sleep -Milliseconds 500 +[System.Windows.Forms.SendKeys]::SendWait("(%{F4})") \ No newline at end of file From 7177b3d400514c1787ffd68c0be55fe4e4aa4829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 15 Nov 2024 21:59:59 +0100 Subject: [PATCH 14/41] ffmpeg for audio+image (youtube) --- media/ffmpeg.ps1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/media/ffmpeg.ps1 b/media/ffmpeg.ps1 index 3e8de0a..ef67ba2 100644 --- a/media/ffmpeg.ps1 +++ b/media/ffmpeg.ps1 @@ -1,4 +1,5 @@ # https://ffmpeg.org/ffmpeg.html + # Takes two files (audio, video) and combine them together into mp4 file. # As audio is shorter add offset to the video so it can sync with audio # @@ -19,4 +20,16 @@ ffmpeg -y -itsoffset 0.2 -i v.webm -i a.mp4 -map 0:0 -map 1:0 -c copy oFilename. # -ar rate set audio sampling rate (in Hz) # -ac channels set number of audio channels # -ab bitrate audio bitrate (please use -b:a) -ffmpeg -i "$($_.FullName)" -vn -ar 44100 -ac 2 -b:a 192k "$($_.FullName.Replace('.wav','.mp3'))" \ No newline at end of file +ffmpeg -i "$($_.FullName)" -vn -ar 44100 -ac 2 -b:a 192k "$($_.FullName.Replace('.wav','.mp3'))" + + +# Takes two files (audio, image) and combine them together into mp4 file. +# -loop 1 - loop the input image infinitely (1 - loop, 0 - no loop) +# -i img.jpg - specifies an input file (image) +# -i audio.mp3 - second input file (MP3 audio) +# -c:v libx264 - specifies the video codec +# -c:a aac - specifies the audio codec. aac is a standard codec for MP4 files, offering good quality at lower bitrates. +# -b:a 320k - sets the audio bitrate +# -shortest - this option ensures that the output video will be as long as the shortest input. +# output.mp4 - name of the output video file +ffmpeg -loop 1 -i img.jpg -i audio.mp3 -c:v libx264 -c:a aac -b:a 320k -shortest output.mp4 \ No newline at end of file From dec8ee3018b8f2e0208e0cf094b374bb7d85154f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 12 Jan 2025 08:51:11 +0100 Subject: [PATCH 15/41] Disable 'Connected Devices Platform Service' --- ...le-connected-devices-platform-services.ps1 | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 system-setup/disable-connected-devices-platform-services.ps1 diff --git a/system-setup/disable-connected-devices-platform-services.ps1 b/system-setup/disable-connected-devices-platform-services.ps1 new file mode 100644 index 0000000..f9d5144 --- /dev/null +++ b/system-setup/disable-connected-devices-platform-services.ps1 @@ -0,0 +1,51 @@ +# Potential problems: +# WON'T WORK +# - timeline WIN+TAB +# MIGHT NOT WORK +# - clipboard history sharing between devices +# - Bluetooth file sharing +# - Windows Night Light + +Clear-Host +$Error.Clear() + +function Disable-CDPUserSvcViaRegistry { + $baseRegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Services" + $cdpServices = Get-ChildItem -Path $baseRegistryPath | Where-Object { $_.Name -match "CDPUserSvc" } + + foreach ($service in $cdpServices) { + Write-Host "Processing service: $($service.PSChildName)" -ForegroundColor Yellow + try { + # Set the 'Start' value to 4 (Disabled) at the root of the service key + Set-ItemProperty -Path $service.PSPath -Name "Start" -Value 4 -ErrorAction Stop + Write-Host "`tSuccessfully disabled service: $($service.PSChildName)" -ForegroundColor Green + } + catch { + Write-Host "`tFailed to modify service: $($service.PSChildName). Error: $($_.Exception.Message)" -ForegroundColor Red + } + } +} + +# Disable and stop CDPUserSvc +Get-Service -Name 'CDPUserSvc*' | ForEach-Object { + Stop-Service -Name $_.Name -Force + try { + Set-Service -Name $_.Name -StartupType Disabled -ErrorAction Stop + } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] { + Disable-CDPUserSvcViaRegistry + } +} + +# Disable and stop CDPSvc +Write-Host "Processing service: CDPSvc" -ForegroundColor Yellow +Stop-Service -Name CDPSvc -Force + +try { + Set-Service -Name CDPSvc -StartupType Disabled + Write-Host "`tSuccessfully disabled service: CDPSvc" -ForegroundColor Green + +} +catch [Microsoft.PowerShell.Commands.ServiceCommandException] { + write-host "`tFailed to modify service: CDPSvc. Error: $($_.Exception.Message)" -ForegroundColor Red +} \ No newline at end of file From f82c2872ffd21853bd2bb59d340a81eae7b45a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 24 Jan 2025 00:42:00 +0100 Subject: [PATCH 16/41] Added ConvertFrom-Gzip cmdlet --- filesystem/gzip.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 filesystem/gzip.ps1 diff --git a/filesystem/gzip.ps1 b/filesystem/gzip.ps1 new file mode 100644 index 0000000..d7063b2 --- /dev/null +++ b/filesystem/gzip.ps1 @@ -0,0 +1,33 @@ +function ConvertFrom-Gzip { + Param ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [ValidateScript( { (Get-Item $_).Name.EndsWith(".gz") })] + [System.IO.FileInfo] + $InputObject, + + [Parameter(Mandatory = $false)] + [switch] + $RemoveInputFile + ) + Process { + # Create a new file and open a filestream for it + $NewFilename = $InputObject.FullName.Remove($InputObject.FullName.Length - $InputObject.Extension.Length) + $DecompressedFileStream = [System.IO.File]::Create($NewFilename) + + # Open the compressed file and copy the file to the decompressed stream + $CompressedFileStream = $InputObject.OpenRead() + $GZipStream = [System.IO.Compression.GZipStream]::new($CompressedFileStream, [System.IO.Compression.CompressionMode]::Decompress) + $GZipStream.CopyTo($DecompressedFileStream) + + # Cleanup + $DecompressedFileStream.Dispose() + $GZipStream.Dispose() + $CompressedFileStream.Dispose() + $DecompressedFileStream, $GZipStream, $CompressedFileStream = $null + + # Remove the initial file if requested. + if ($PSBoundParameters.ContainsKey('RemoveInputFile')) { + $InputObject.Delete() + } + } +} \ No newline at end of file From dc047ef1456ffaee7fd8d09dc21735cf27a7a101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Thu, 6 Feb 2025 00:34:56 +0100 Subject: [PATCH 17/41] Environment Variable usage and lifetimes --- development/environment-variables.ps1 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 development/environment-variables.ps1 diff --git a/development/environment-variables.ps1 b/development/environment-variables.ps1 new file mode 100644 index 0000000..47aeb99 --- /dev/null +++ b/development/environment-variables.ps1 @@ -0,0 +1,23 @@ +# Environment Variable Lifetimes + +# 1. Session ($env:VARIABLE) +$env:MY_VAR = "value1" +Write-Host $env:MY_VAR + +# 1.1. Environment variable with dynamic key +$key = "MY_VAR" +Set-Item "env:$key" "value2" + +# 2. Process-Level Inheritance +# when you set an environment variable in PowerShell, +# it is inherited by child processes (like dotnet run, git, or other spawned applications). + +# 3. Permanent Environment Variables (Registry) +[System.Environment]::SetEnvironmentVariable("MY_VAR", "value1", "User") +Write-Host $env:MY_VAR + +# 4. Environment Variables in GitHubs Actions +# Environment variables set during one step are not automatically available in subsequent steps in GitHub Actions. +# To persist environment variables between steps, you need to explicitly use the GITHUB_ENV file. +$value = "value1" +echo "$key=$value" >> $env:GITHUB_ENV \ No newline at end of file From fd53712bbc21dfe8d7893c0658f2c41a0a9cda8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 7 Feb 2025 00:46:41 +0100 Subject: [PATCH 18/41] Color inversion with ffmpeg --- media/color-inversion.md | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 media/color-inversion.md diff --git a/media/color-inversion.md b/media/color-inversion.md new file mode 100644 index 0000000..927a9ce --- /dev/null +++ b/media/color-inversion.md @@ -0,0 +1,43 @@ +# Color inversion with ffmpeg + +```powershell +ffmpeg -i input.mp4 -vf "negate,hue=h=180,eq=contrast=1.2:saturation=1.1" output.mp4 +``` +## Demo +#### Before + + + + +https://github.com/user-attachments/assets/a6969533-a1f9-4a8f-9203-dd151f4c6aa7 + +#### After + + + + +https://github.com/user-attachments/assets/16785da7-4ed3-48c5-ad3e-b1223987c49e + + +## Explanation +The `-i input.mp4` part specifies the input file. + +The `-vf` flag stands for "video filter," and it is followed by a series of filters applied to the video. + +The filters are: + +- `negate`: This filter inverts the colors of the video, creating a negative effect. +- `hue=h=180`: This filter adjusts the hue of the video by 180 degrees, effectively rotating the color wheel to change the overall color tone. +- `eq=contrast=1.2:saturation=1.1`: This filter adjusts the contrast and saturation of the video. The contrast=1.2 increases the contrast by 20%, making the darks darker and the lights lighter. The saturation=1.1 increases the saturation by 10%, making the colors more vivid. + + + +Combining these filters results in a video with inverted colors, a shifted hue, and enhanced contrast and saturation. The processed video is then saved as output.mp4. + + +*[source: +Rubber Duck Thursdays!](https://www.youtube.com/watch?v=o7b6t6uZJPA)* \ No newline at end of file From 217e81ea845cabdef265fed0f76cf9da8ba006ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Thu, 13 Feb 2025 20:46:25 +0100 Subject: [PATCH 19/41] GitHub API --- git/github-api.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 git/github-api.ps1 diff --git a/git/github-api.ps1 b/git/github-api.ps1 new file mode 100644 index 0000000..8734b15 --- /dev/null +++ b/git/github-api.ps1 @@ -0,0 +1,14 @@ +Clear-Host +$PersonalAccessToken = "github_pat_[your_personal_access_token]" + +$GitHubApiUrl = "https://api.github.com/user/repos" +# $GitHubApiUrl = "https://api.github.com/orgs/PowerShellLibrary/repos" +# $GitHubApiUrl = "https://api.github.com/repositories" + +$Headers = @{ + Authorization = "token $PersonalAccessToken" + "User-Agent" = "PowerShell" # GitHub API requires a User-Agent header +} + +$response = Invoke-RestMethod -Uri $GitHubApiUrl -Method Get -Headers $Headers +$response From 1f0bf465ba7d2140f8d73bba8ca876d7adc50a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Mon, 24 Feb 2025 23:07:20 +0100 Subject: [PATCH 20/41] Added remove-non-ASCII-characters --- strings/remove-non-ASCII-characters.ps1 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 strings/remove-non-ASCII-characters.ps1 diff --git a/strings/remove-non-ASCII-characters.ps1 b/strings/remove-non-ASCII-characters.ps1 new file mode 100644 index 0000000..6397047 --- /dev/null +++ b/strings/remove-non-ASCII-characters.ps1 @@ -0,0 +1,2 @@ +$inputString = "żółć gęślą jaźń" +[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($inputString)) \ No newline at end of file From 0cff518d47ccc7feb810af00b5568bb65002f18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Mon, 24 Feb 2025 23:22:12 +0100 Subject: [PATCH 21/41] Added touch-image --- media/touch-image.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 media/touch-image.ps1 diff --git a/media/touch-image.ps1 b/media/touch-image.ps1 new file mode 100644 index 0000000..0b94ddc --- /dev/null +++ b/media/touch-image.ps1 @@ -0,0 +1,16 @@ +# Use case: modify media items without changing their visual content + +# Usage: touch all PNG files in the images directory +# Get-ChildItem ".\themes\images\" -Filter *.png -Recurse | ForEach-Object { Touch-File $_.FullName } + + +function Touch-File { + param ([string]$filePath) + + $bytes = [System.IO.File]::ReadAllBytes($filePath) + + # Append a harmless zero byte + $bytes += 0x00 + + [System.IO.File]::WriteAllBytes($filePath, $bytes) +} \ No newline at end of file From a8a1bf06480cd578aa190952ff6485968609f658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 4 Mar 2025 23:18:50 +0100 Subject: [PATCH 22/41] Added dotnet-publish.ps1 --- development/.net/dotnet-publish.ps1 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 development/.net/dotnet-publish.ps1 diff --git a/development/.net/dotnet-publish.ps1 b/development/.net/dotnet-publish.ps1 new file mode 100644 index 0000000..b79516d --- /dev/null +++ b/development/.net/dotnet-publish.ps1 @@ -0,0 +1,3 @@ +dotnet publish -r win-x64 --self-contained -p:PublishSingleFile=true -c Release -o ./publish/win +dotnet publish -r linux-x64 --self-contained -p:PublishSingleFile=true -c Release -o ./publish/linux +dotnet publish -r osx-x64 --self-contained -p:PublishSingleFile=true -c Release -o ./publish/osx \ No newline at end of file From e9370b8a7314382c87642a207f69f250ba95c0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 9 Mar 2025 07:45:39 +0100 Subject: [PATCH 23/41] Added firewall-rules --- system-setup/firewall-rules.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 system-setup/firewall-rules.ps1 diff --git a/system-setup/firewall-rules.ps1 b/system-setup/firewall-rules.ps1 new file mode 100644 index 0000000..9660b8f --- /dev/null +++ b/system-setup/firewall-rules.ps1 @@ -0,0 +1,17 @@ +# Block a ABCD.exe from accessing the Internet using Windows Defender Firewall +$exePath = "C:\Users\Alan\AppData\Local\Programs\ABCD\ABCD.exe" + +# Add outbound rule to block ABCD.exe +New-NetFirewallRule -DisplayName "[Block] ABCD Out" -Direction Outbound -Program $exePath -Action Block + +# Add inbound rule to block ABCD.exe +New-NetFirewallRule -DisplayName "[Block] ABCD In" -Direction Inbound -Program $exePath -Action Block + +# Enable rules +Get-NetFirewallRule -DisplayName "[Block] ABCD" | Set-NetFirewallRule -Enabled True + +# Disable the inbound rule +Get-NetFirewallRule -DisplayName "*Block* ABCD In" | Set-NetFirewallRule -Enabled False + +# Remove rules +Get-NetFirewallRule -DisplayName '*ABCD*' | Remove-NetFirewallRule \ No newline at end of file From aa09cfa4dc4aaa3d0781d51b8649976122fe7a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 9 Mar 2025 08:15:04 +0100 Subject: [PATCH 24/41] Added Process Monitor (procmon) --- .../procmon/ProcmonConfigurationObsidian.pmc | Bin 0 -> 2298 bytes monitoring/procmon/procmon-cli.ps1 | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 monitoring/procmon/ProcmonConfigurationObsidian.pmc create mode 100644 monitoring/procmon/procmon-cli.ps1 diff --git a/monitoring/procmon/ProcmonConfigurationObsidian.pmc b/monitoring/procmon/ProcmonConfigurationObsidian.pmc new file mode 100644 index 0000000000000000000000000000000000000000..26c162dfb9c7470cdcb31c8d4852e67f04aa054f GIT binary patch literal 2298 zcmds&OKTHR6vt1BpcEG(MMS#DqDT=M~ce4mSf{)=( z@Cn?9PvNidH~4?0DuE^We1W`b`&P3Jt8nTa+aXJl9WcLQi&nHZwrQ`xY$FvI7wjFp zXKR+X$F{&s;PxNH`*VyNJm;~MEMH}Pi<7EZ)#|KO7<=tqByCCgWSKZB5M#V6a#Sk-fgza?^cNDh?2-}&)lf(RpHtAM=0`$sm=-%FfGLmElk;+gv?7A!t@A1bJ>b*ntIq!Y2jnr)q*>^;) z4~QYcuaMh6$J0d8jm{y}f-6xXX}w<(N2Y-OshXsD08|<3sB0MYCDqq@Oaqww^ckxV zRKZn{LTV;Rz8A1EtUI6z9Pe+xZQt~n^s`% W6v@*(AKB2&^S5YxhoWeCxcvmh`u@5A literal 0 HcmV?d00001 diff --git a/monitoring/procmon/procmon-cli.ps1 b/monitoring/procmon/procmon-cli.ps1 new file mode 100644 index 0000000..45b6612 --- /dev/null +++ b/monitoring/procmon/procmon-cli.ps1 @@ -0,0 +1,17 @@ +# This script is used to start Process Monitor in the background with a specific configuration file. +# https://learn.microsoft.com/en-us/sysinternals/downloads/procmon + +procmon.exe /Quiet /Minimized /LoadConfig ProcmonConfigurationObsidian.pmc /Backingfile MonitorLog.pml + +# Configuration File: ProcmonConfigurationObsidian.pmc + +# Monitoring Activities +# Show Process and Thread Activity +# Show Network Activity + +# Capture Events (Drop filtered events) +# Filters +# - ✅Process Name is Obsidian.exe +# - ❌Operation is NOT Thread Create +# - ❌Operation is NOT Thread Exit +# - ❌Operation is NOT Load Image \ No newline at end of file From 8339b6a9a6b0b0efe53ea6cbebc11a2e542adab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 11 Mar 2025 20:52:58 +0100 Subject: [PATCH 25/41] Added refresh-debian --- wsl/refresh-debian.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 wsl/refresh-debian.ps1 diff --git a/wsl/refresh-debian.ps1 b/wsl/refresh-debian.ps1 new file mode 100644 index 0000000..3cb0449 --- /dev/null +++ b/wsl/refresh-debian.ps1 @@ -0,0 +1,6 @@ +# Refresh Debian WSL distribution by unregistering and reinstalling it. +# This is useful when the distribution is corrupted or when you want to reset it. + +wsl -l -v +wsl --unregister Debian +wsl --install -d Debian \ No newline at end of file From 65a6ec5f91a25b3cf9eaaa038178ffa1151162f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 11 Mar 2025 22:41:59 +0100 Subject: [PATCH 26/41] Generics in PowerShell --- development/ps/generic.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 development/ps/generic.ps1 diff --git a/development/ps/generic.ps1 b/development/ps/generic.ps1 new file mode 100644 index 0000000..a7d2dfa --- /dev/null +++ b/development/ps/generic.ps1 @@ -0,0 +1,12 @@ +# Workaround to call to a generic method OfType() in PowerShell, when PowerShell cannot figure out from the context + +# Method 1 - using OfType method +[System.Linq.Enumerable]::OfType[int](@(1, 2, 'a')) + +# Method 2 - using reflection +$method = [System.Linq.Enumerable].GetMethod('OfType') +$genericMethod = $method.MakeGenericMethod([int]) +$genericMethod.Invoke($null, @(, @(1, 2, 'a'))) + +# Example of using Distinct method +[System.Linq.Enumerable]::Distinct([int[]]@(1, 2, 3, 1, 2)) \ No newline at end of file From 00bc7de30985f357920f0b56265778d3597310fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 14 Mar 2025 22:49:46 +0100 Subject: [PATCH 27/41] Added git snippets --- git/add-submodule.ps1 | 3 +++ git/git-snippets.ps1 | 2 ++ git/specify-user.ps1 | 3 +++ git/worktree.ps1 | 8 ++++++++ 4 files changed, 16 insertions(+) create mode 100644 git/add-submodule.ps1 create mode 100644 git/git-snippets.ps1 create mode 100644 git/specify-user.ps1 create mode 100644 git/worktree.ps1 diff --git a/git/add-submodule.ps1 b/git/add-submodule.ps1 new file mode 100644 index 0000000..853cfe8 --- /dev/null +++ b/git/add-submodule.ps1 @@ -0,0 +1,3 @@ +# Add new submodule +git submodule add git://github.com/jquery/jquery.git externals/jquery +git submodule update --init --recursive \ No newline at end of file diff --git a/git/git-snippets.ps1 b/git/git-snippets.ps1 new file mode 100644 index 0000000..168d02b --- /dev/null +++ b/git/git-snippets.ps1 @@ -0,0 +1,2 @@ +# create a new Git branch based on a specific commit SHA +git checkout -b BRANCH_NAME COMMIT_SHA \ No newline at end of file diff --git a/git/specify-user.ps1 b/git/specify-user.ps1 new file mode 100644 index 0000000..4bac4be --- /dev/null +++ b/git/specify-user.ps1 @@ -0,0 +1,3 @@ +## Specify user +git config user.name "AuthorExample" +git config user.email "ae@duck.com" \ No newline at end of file diff --git a/git/worktree.ps1 b/git/worktree.ps1 new file mode 100644 index 0000000..fa9e9f4 --- /dev/null +++ b/git/worktree.ps1 @@ -0,0 +1,8 @@ +# list all worktrees +git worktree list + +# add a worktree to folder _branch using branch 'issues/templates_enabled_flag' +git worktree add _branch issues/templates_enabled_flag + +# remove a worktree from folder _branch +git worktree remove _branch From 2dd702fe5515207d833d81ba82cd2b13579258d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Wed, 19 Mar 2025 23:47:44 +0100 Subject: [PATCH 28/41] generate SSH key snipept --- git/setup-ssh-for-git.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git/setup-ssh-for-git.ps1 b/git/setup-ssh-for-git.ps1 index a4c5d68..4e21da6 100644 --- a/git/setup-ssh-for-git.ps1 +++ b/git/setup-ssh-for-git.ps1 @@ -1,6 +1,10 @@ # Prerequisites - you need to get SSH key supported by your git hosting service. # deploy it into: c:\id_rsa +# generate SSH key +ssh-keygen -t rsa -b 4096 -C "key-comment" # 4096 RSA key (SHA256) +ssh-keygen -t ed25519 -C "key-comment" + # install choco Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) From 2ccba14614199da8f5dd1b6ab65388a62ad6c509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Wed, 19 Mar 2025 23:56:19 +0100 Subject: [PATCH 29/41] [debian] install-pwsh --- wsl/install-pwsh.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 wsl/install-pwsh.sh diff --git a/wsl/install-pwsh.sh b/wsl/install-pwsh.sh new file mode 100644 index 0000000..b33e0d4 --- /dev/null +++ b/wsl/install-pwsh.sh @@ -0,0 +1,22 @@ +# Source: https://learn.microsoft.com/en-us/powershell/scripting/install/install-debian?view=powershell-7.5 + +# Update the list of packages +sudo apt-get update + +# Install pre-requisite packages. +sudo apt-get install -y wget + +# Download the PowerShell package file +wget https://github.com/PowerShell/PowerShell/releases/download/v7.5.0/powershell_7.5.0-1.deb_amd64.deb + +# Install the PowerShell package +sudo dpkg -i powershell_7.5.0-1.deb_amd64.deb + +# Resolve missing dependencies and finish the install (if necessary) +sudo apt-get install -f + +# Delete the downloaded package file +rm powershell_7.5.0-1.deb_amd64.deb + +# Start PowerShell +pwsh \ No newline at end of file From 30f49b7eb219b6d4614dd511695a94304165e0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 21 Mar 2025 23:25:18 +0100 Subject: [PATCH 30/41] Added set-env-PATH --- system-setup/set-env-PATH.ps1 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 system-setup/set-env-PATH.ps1 diff --git a/system-setup/set-env-PATH.ps1 b/system-setup/set-env-PATH.ps1 new file mode 100644 index 0000000..1a3d9e0 --- /dev/null +++ b/system-setup/set-env-PATH.ps1 @@ -0,0 +1,4 @@ +# This script will add a tool folder path to the system environment variable (PATH) +$tool = "C:\tools\dsc" +$PATH = [Environment]::GetEnvironmentVariable("PATH") +[Environment]::SetEnvironmentVariable("PATH", "$PATH;$tool", [System.EnvironmentVariableTarget]::Machine) \ No newline at end of file From 614c1d7b4ffa16220a307957b981b6c74b09fd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 23 Mar 2025 09:56:32 +0100 Subject: [PATCH 31/41] Desired State Configuration 3.0 --- dsc/README.md | 3 ++ dsc/run.ps1 | 32 +++++++++++++++++++ .../ExtensionManifestV2Availability.dsc.yml | 9 ++++++ dsc/validate.dsc.yml | 8 +++++ 4 files changed, 52 insertions(+) create mode 100644 dsc/README.md create mode 100644 dsc/run.ps1 create mode 100644 dsc/steps/ExtensionManifestV2Availability.dsc.yml create mode 100644 dsc/validate.dsc.yml diff --git a/dsc/README.md b/dsc/README.md new file mode 100644 index 0000000..f326fc4 --- /dev/null +++ b/dsc/README.md @@ -0,0 +1,3 @@ +# Desired State Configuration 3.0 + +- [ExtensionManifestV2Availability.dsc](https://developer.chrome.com/docs/extensions/develop/migrate/mv2-deprecation-timeline) - enable support for chrome extensions V2 \ No newline at end of file diff --git a/dsc/run.ps1 b/dsc/run.ps1 new file mode 100644 index 0000000..c188cce --- /dev/null +++ b/dsc/run.ps1 @@ -0,0 +1,32 @@ +$validation = dsc config test -f .\validate.dsc.yml -o json | ConvertFrom-Json +foreach ($r in $validation.results) { + if ($r.result.inDesiredState -eq $false) { + throw "[FAIL] $($r.name) [$($r.type)]" + } +} + +Get-ChildItem .\steps -Filter '*.dsc.yml' -Recurse | ForEach-Object { + $step = $_.FullName + Write-Host "[INFO] Running step: $step" -ForegroundColor DarkGray + $test = dsc config test -f $step -o json | ConvertFrom-Json + $test.results | % { + if ($_.result.inDesiredState -eq $true) { + Write-Host "[OK] $($_.name) [$($_.type)]" -ForegroundColor Green + } + else { + Write-Host "[APPLY] $($_.name) [$($_.type)]" -ForegroundColor Yellow + } + } + + [bool[]]$states = $test.results.result.inDesiredState + if ( $states.Contains($false)) { + $setResult = dsc config set -f $step -o json | ConvertFrom-Json + if ($LASTEXITCODE -ne 0) { + throw "[FATAL] Couldn't set the desired state for $step" + } + } +} + +if ($LASTEXITCODE -eq 0) { + Write-Host "[PASS] All resources are in desired state" -ForegroundColor Green +} \ No newline at end of file diff --git a/dsc/steps/ExtensionManifestV2Availability.dsc.yml b/dsc/steps/ExtensionManifestV2Availability.dsc.yml new file mode 100644 index 0000000..8b2470b --- /dev/null +++ b/dsc/steps/ExtensionManifestV2Availability.dsc.yml @@ -0,0 +1,9 @@ +$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json +resources: + - name: Manifest V2 Availability + type: Microsoft.Windows/Registry + properties: + keyPath: HKLM\SOFTWARE\Policies\Google\Chrome\ + valueName: ExtensionManifestV2Availability + valueData: + DWord: 2 \ No newline at end of file diff --git a/dsc/validate.dsc.yml b/dsc/validate.dsc.yml new file mode 100644 index 0000000..c1b57aa --- /dev/null +++ b/dsc/validate.dsc.yml @@ -0,0 +1,8 @@ +$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json + +resources: + - name: Validate the OS is Windows + type: Microsoft/OSInfo + properties: + family: Windows + From 81f68e117a91f1ef1f78314d3359d5f313d0beb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 23 Mar 2025 14:19:07 +0100 Subject: [PATCH 32/41] Cheat Sheet: tmux --- debian/tmux.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 debian/tmux.md diff --git a/debian/tmux.md b/debian/tmux.md new file mode 100644 index 0000000..0590dbb --- /dev/null +++ b/debian/tmux.md @@ -0,0 +1,53 @@ +# Cheat Sheet: tmux + +### 🏆 **Basic Commands:** + +```bash +tmux new -s abc # Create a new session named "abc" +tmux ls # List all sessions +tmux attach -t abc # Attach to a session +tmux detach # Detach (Ctrl + B, then D also works) +tmux switch-client -t abc # switch to the other session without nesting +tmux kill-session -t abc # Kill a session +tmux kill-server # Kill all sessions +``` + +--- + +### ⚙️ **Pane Management:** + +| Action | Shortcut | +| ----------------------------------- | ---------------------- | +| **Split vertically (left/right)** | `Ctrl + B` → `%` | +| **Split horizontally (top/bottom)** | `Ctrl + B` → `"` | +| **Switch panes** | `Ctrl + B` → Arrow key | +| **Close current pane** | `Ctrl + D` | +| **Resize pane** | `Ctrl + B` → `:` then: | +| Shrink down | `resize-pane -D 5` | +| Shrink up | `resize-pane -U 5` | +| Shrink left | `resize-pane -L 5` | +| Shrink right | `resize-pane -R 5` | + +--- + +### 🌐 **Window (Tab) Management:** + +| Action | Shortcut | +| -------------------- | ---------------- | +| **List windows** | `Ctrl + B` → `W` | +| **Rename window** | `Ctrl + B` → `,` | +| **New window (tab)** | `Ctrl + B` → `C` | +| **Next window** | `Ctrl + B` → `N` | +| **Previous window** | `Ctrl + B` → `P` | +| **Close window** | `Ctrl + B` → `&` | + +--- + +### 📌 **Session Management:** + +| Action | Shortcut | +| ----------------------- | ------------------------------------- | +| **Detach from session** | `Ctrl + B` → `D` | +| **Switch sessions** | `Ctrl + B` → `S` | +| **Rename session** | `Ctrl + B` → `$` | +| **Kill session** | `Ctrl + B` → `:` then: `kill-session` | From d5809890236cafe2ad0a495439ffa54ea3abd3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 6 May 2025 17:45:52 +0200 Subject: [PATCH 33/41] Add script to generate CPU load for testing --- debian/gen-cpu-load.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 debian/gen-cpu-load.sh diff --git a/debian/gen-cpu-load.sh b/debian/gen-cpu-load.sh new file mode 100644 index 0000000..4c8645f --- /dev/null +++ b/debian/gen-cpu-load.sh @@ -0,0 +1,3 @@ +yes > /dev/null & +sleep 50 +kill $! From 203a5c92c2c8ab7a8a70215778bbaa49b2ee052c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Tue, 6 May 2025 17:54:19 +0200 Subject: [PATCH 34/41] Add installation script for Docker on Debian --- debian/install-docker.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 debian/install-docker.sh diff --git a/debian/install-docker.sh b/debian/install-docker.sh new file mode 100644 index 0000000..4c2fc6a --- /dev/null +++ b/debian/install-docker.sh @@ -0,0 +1,17 @@ +# Add Docker's official GPG key: +sudo apt-get update +sudo apt-get install ca-certificates curl +sudo install -m 0755 -d /etc/apt/keyrings +sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc +sudo chmod a+r /etc/apt/keyrings/docker.asc + +# Add the repository to Apt sources: +ARCH=$(dpkg --print-architecture) +CODENAME=$(source /etc/os-release && echo "$VERSION_CODENAME") +REPO_URL="deb [arch=$ARCH signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $CODENAME stable" +echo "$REPO_URL" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + +sudo apt-get update + +# Install latest version +sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \ No newline at end of file From aa0e0e47b594d640235fac14f40a0bea2cd90f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 4 May 2025 19:16:16 +0200 Subject: [PATCH 35/41] pihole sql helpers --- sql/pihole/adlist-unique-domains.sql | 25 +++++++++++++++++++++++ sql/pihole/globally-unique-domains.sql | 28 ++++++++++++++++++++++++++ sql/pihole/trim-domain.sql | 6 ++++++ 3 files changed, 59 insertions(+) create mode 100644 sql/pihole/adlist-unique-domains.sql create mode 100644 sql/pihole/globally-unique-domains.sql create mode 100644 sql/pihole/trim-domain.sql diff --git a/sql/pihole/adlist-unique-domains.sql b/sql/pihole/adlist-unique-domains.sql new file mode 100644 index 0000000..8a8b4f7 --- /dev/null +++ b/sql/pihole/adlist-unique-domains.sql @@ -0,0 +1,25 @@ +-- This SQL query retrieves the number of unique domains and total domains for each adlist from the vw_gravity view. +-- It calculates the uniqueness percentage and orders the results by this percentage in ascending order. + +SELECT + adlist_id, + COUNT(DISTINCT domain) AS unique_domains, + COUNT(domain) AS total_domains, + ROUND(CAST(COUNT(DISTINCT domain) AS FLOAT) / COUNT(domain) * 100, 2) AS uniqueness_percent +FROM + vw_gravity +GROUP BY + adlist_id +ORDER BY + uniqueness_percent ASC; + + +-- Example output: +-- adlist_id unique_domains total_domains uniqueness_percent +-- 7 30873 31461 98.13 +-- 6 42363 42536 99.59 +-- 1 106610 106611 100.0 +-- 2 2194 2194 100.0 +-- 3 162079 162079 100.0 +-- 4 319548 319548 100.0 +-- 5 307383 307383 100.0 \ No newline at end of file diff --git a/sql/pihole/globally-unique-domains.sql b/sql/pihole/globally-unique-domains.sql new file mode 100644 index 0000000..060fe39 --- /dev/null +++ b/sql/pihole/globally-unique-domains.sql @@ -0,0 +1,28 @@ +-- This SQL query calculates the percentage of globally unique domains in each adlist from the vw_gravity view. +-- Run trim-domain.sql before executing this query to ensure that the domain field is clean and trimmed. +SELECT + g1.adlist_id, + COUNT(*) AS total_domains, + SUM(CASE WHEN dup_counts.domain_count = 1 THEN 1 ELSE 0 END) AS globally_unique_domains, + ROUND(SUM(CASE WHEN dup_counts.domain_count = 1 THEN 1.0 ELSE 0 END) / COUNT(*) * 100, 2) AS uniqueness_percent +FROM + vw_gravity g1 +JOIN ( + SELECT domain, COUNT(DISTINCT adlist_id) AS domain_count + FROM vw_gravity + GROUP BY domain +) dup_counts ON g1.domain = dup_counts.domain +GROUP BY + g1.adlist_id +ORDER BY + uniqueness_percent DESC; + +-- Example output: +-- adlist_id total_domains globally_unique_domains uniqueness_percent +-- 4 319548 319548 100.0 +-- 2 2194 2194 100.0 +-- 7 31461 29665 94.29 +-- 1 106611 100485 94.25 +-- 6 42536 38253 89.93 +-- 5 307383 249377 81.13 +-- 3 162079 96220 59.37 \ No newline at end of file diff --git a/sql/pihole/trim-domain.sql b/sql/pihole/trim-domain.sql new file mode 100644 index 0000000..1c66bb1 --- /dev/null +++ b/sql/pihole/trim-domain.sql @@ -0,0 +1,6 @@ +-- Trim leading and trailing characters from the domain field in the gravity table +UPDATE gravity +SET domain = TRIM( + TRIM(SUBSTR(domain, CASE WHEN domain LIKE '||%' THEN 3 ELSE 1 END), '^') + ) +WHERE adlist_id = 26; \ No newline at end of file From 02ef148bd011e9ff4dd3a8d6f19c4fc81e58d712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 11 May 2025 14:55:26 +0200 Subject: [PATCH 36/41] ffmpeg: crop video from the top --- media/ffmpeg.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/media/ffmpeg.ps1 b/media/ffmpeg.ps1 index ef67ba2..8f33229 100644 --- a/media/ffmpeg.ps1 +++ b/media/ffmpeg.ps1 @@ -32,4 +32,16 @@ ffmpeg -i "$($_.FullName)" -vn -ar 44100 -ac 2 -b:a 192k "$($_.FullName.Replace( # -b:a 320k - sets the audio bitrate # -shortest - this option ensures that the output video will be as long as the shortest input. # output.mp4 - name of the output video file -ffmpeg -loop 1 -i img.jpg -i audio.mp3 -c:v libx264 -c:a aac -b:a 320k -shortest output.mp4 \ No newline at end of file +ffmpeg -loop 1 -i img.jpg -i audio.mp3 -c:v libx264 -c:a aac -b:a 320k -shortest output.mp4 + +# Crop video from the top +# This command crops the video by removing 440 pixels from the top, effectively shifting the video down by that amount. +# -i input.mp4 - specifies the input video file +# -vf "crop=iw:ih-440:0:440" - applies a video filter (vf) to crop the video. +# - iw Input width (keeps the full width of the video). +# - ih-440 Input height minus 440 pixels +# - 0 X offset (starts cropping from the left edge). +# - 440 Y offset (starts cropping from 440 pixels down from the top). +# -c:a copy - copies the audio stream without re-encoding it +# output.mp4 - name of the output video file +ffmpeg -i .\input.mp4 -vf "crop=iw:ih-440:0:440" -c:a copy output.mp4 \ No newline at end of file From ecd28b9e713d2ccc3bd7dc922b3b95307291cefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 11 May 2025 16:05:48 +0200 Subject: [PATCH 37/41] Download specific nuget.exe version --- development/ci/get-nuget.ps1 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 development/ci/get-nuget.ps1 diff --git a/development/ci/get-nuget.ps1 b/development/ci/get-nuget.ps1 new file mode 100644 index 0000000..1666945 --- /dev/null +++ b/development/ci/get-nuget.ps1 @@ -0,0 +1,3 @@ +$nugetVersion = "6.7.0" # Change to your required version +$nugetUrl = "https://dist.nuget.org/win-x86-commandline/v$nugetVersion/nuget.exe" +Invoke-WebRequest -Uri $nugetUrl -OutFile "nuget.exe" \ No newline at end of file From c47a61bca5de986e7b05ac9659ddd4669cbe3f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Fri, 21 Nov 2025 22:51:49 +0100 Subject: [PATCH 38/41] Add script for local HTTPS dev setup --- security/local-https-dev-setup.ps1 | 134 +++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 security/local-https-dev-setup.ps1 diff --git a/security/local-https-dev-setup.ps1 b/security/local-https-dev-setup.ps1 new file mode 100644 index 0000000..44c7f1a --- /dev/null +++ b/security/local-https-dev-setup.ps1 @@ -0,0 +1,134 @@ +# --------------------------------------------- +# LOCAL HTTPS SETUP FOR DEVELOPMENT +# --------------------------------------------- + +$ErrorActionPreference = "Stop" + +# --- CONFIG --- +$dns = "localhost" +$port = 19456 +$friendlyName = "Dev Local HTTPS Cert" + +$storeLocationRoot = "LocalMachine" +$storeNameRoot = "Root" + +$storeLocationMy = "LocalMachine" +$storeNameMy = "My" + +$prefix = "https://$dns`:$port/" + +Write-Host "==============================================" +Write-Host " HTTPS Setup for Local Secure Communication " +Write-Host "==============================================" +Write-Host "" + +# Ensure administrator +if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + + Write-Host "[ERROR] This script must be run as Administrator." -ForegroundColor Red + exit 1 +} + +# --------------------------------------------- +# Step 1 — Check/create certificate +# --------------------------------------------- +Write-Host "🔍 Checking for existing certificate..." -ForegroundColor Cyan + +$myStore = New-Object System.Security.Cryptography.X509Certificates.X509Store($storeNameMy, $storeLocationMy) +$myStore.Open("ReadWrite") + +$existingCert = $myStore.Certificates | ? { $_.FriendlyName -eq $friendlyName } + +if ($existingCert) { + Write-Host "✔ Found existing certificate: $friendlyName" -ForegroundColor Green + $cert = $existingCert +} +else { + Write-Host "⏳ Creating new self-signed certificate for '$dns'..." -ForegroundColor Yellow + + $cert = New-SelfSignedCertificate ` + -DnsName $dns, "127.0.0.1" ` + -FriendlyName $friendlyName ` + -CertStoreLocation "Cert:\$storeLocationMy\$storeNameMy" ` + -KeyExportPolicy Exportable ` + -NotAfter (Get-Date).AddYears(5) + + Write-Host "✔ Certificate created successfully!" -ForegroundColor Green +} + +$myStore.Close() + +# --------------------------------------------- +# Step 2 — Ensure certificate is trusted +# --------------------------------------------- +Write-Host "" +Write-Host "🔐 Ensuring certificate is trusted..." -ForegroundColor Cyan + +$rootStore = New-Object System.Security.Cryptography.X509Certificates.X509Store($storeNameRoot, $storeLocationRoot) +$rootStore.Open("ReadWrite") + +$alreadyInRoot = $rootStore.Certificates | +Where-Object { $_.Thumbprint -eq $cert.Thumbprint } + +if ($alreadyInRoot) { + Write-Host "✔ Certificate already trusted (Root store)." -ForegroundColor Green +} +else { + Write-Host "⏳ Adding certificate to Trusted Root..." -ForegroundColor Yellow + $rootStore.Add($cert) + Write-Host "✔ Certificate trusted successfully!" -ForegroundColor Green +} + +$rootStore.Close() + +# --------------------------------------------- +# Step 3 — Clean old HTTPS bindings +# --------------------------------------------- +Write-Host "" +Write-Host "🧹 Cleaning old HTTPS bindings on port $port..." -ForegroundColor Cyan + +try { + netsh http delete sslcert ipport=0.0.0.0:$port | Out-Null + Write-Host "✔ Old bindings removed." -ForegroundColor Green +} +catch { + Write-Host "ℹ No old bindings found." -ForegroundColor DarkGray +} + +# --------------------------------------------- +# Step 4 — Bind certificate to port +# --------------------------------------------- +Write-Host "" +Write-Host "🔗 Binding certificate to port $port..." -ForegroundColor Cyan + +$thumb = $cert.Thumbprint +$appid = [guid]::NewGuid() + +netsh http add sslcert ipport=0.0.0.0:$port certhash=$thumb certstorename=$storeNameMy appid="{$appid}" | Out-Null + +Write-Host "✔ HTTPS binding added successfully!" -ForegroundColor Green + +# --------------------------------------------- +# Step 5 — Summary +# --------------------------------------------- +Write-Host "" +Write-Host "==============================================" +Write-Host " SETUP COMPLETE 🎉" +Write-Host "==============================================" +Write-Host "" +Write-Host "🔒 HTTPS is now enabled for your local server." +Write-Host "" +Write-Host "📜 Details:" +Write-Host " - Hostname: $dns" +Write-Host " - Port: $port" +Write-Host " - Prefix: $prefix" +Write-Host " - Thumbprint: $thumb" +Write-Host " - Cert Name: $friendlyName" +Write-Host "" +Write-Host "🧪 Test it in your browser:" +Write-Host " $prefix" -ForegroundColor Yellow +Write-Host "" +Write-Host "✔ Your Chrome extension should now work without certificate errors." +Write-Host "" +Write-Host "==============================================" +Write-Host "" From da45b0f15498460bbfd8757153be0ea5a99f0db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 30 Nov 2025 09:18:45 +0100 Subject: [PATCH 39/41] Add script to identify motherboard details using WMIC --- windows/identify-motherboard.ps1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 windows/identify-motherboard.ps1 diff --git a/windows/identify-motherboard.ps1 b/windows/identify-motherboard.ps1 new file mode 100644 index 0000000..17a4321 --- /dev/null +++ b/windows/identify-motherboard.ps1 @@ -0,0 +1 @@ +wmic baseboard get product, Manufacturer, version, serialnumber \ No newline at end of file From 997a0edef114d34a9f5ec57bf391ad1d629da01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 18 Jan 2026 06:26:30 +0100 Subject: [PATCH 40/41] ffmpeg: info (ffprobe) and audio extraction from video --- media/ffmpeg.ps1 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/media/ffmpeg.ps1 b/media/ffmpeg.ps1 index 8f33229..898ab7c 100644 --- a/media/ffmpeg.ps1 +++ b/media/ffmpeg.ps1 @@ -34,6 +34,7 @@ ffmpeg -i "$($_.FullName)" -vn -ar 44100 -ac 2 -b:a 192k "$($_.FullName.Replace( # output.mp4 - name of the output video file ffmpeg -loop 1 -i img.jpg -i audio.mp3 -c:v libx264 -c:a aac -b:a 320k -shortest output.mp4 + # Crop video from the top # This command crops the video by removing 440 pixels from the top, effectively shifting the video down by that amount. # -i input.mp4 - specifies the input video file @@ -44,4 +45,21 @@ ffmpeg -loop 1 -i img.jpg -i audio.mp3 -c:v libx264 -c:a aac -b:a 320k -shortest # - 440 Y offset (starts cropping from 440 pixels down from the top). # -c:a copy - copies the audio stream without re-encoding it # output.mp4 - name of the output video file -ffmpeg -i .\input.mp4 -vf "crop=iw:ih-440:0:440" -c:a copy output.mp4 \ No newline at end of file +ffmpeg -i .\input.mp4 -vf "crop=iw:ih-440:0:440" -c:a copy output.mp4 + + +# Inspect media file streams +# ffprobe prints detailed information about the input file, including +# codec, format, bitrate, duration, and stream indexes (video, audio, +# subtitles, etc.). +ffprobe .\input.mp4 + + +# Extract a specific audio stream from a video file to MP3 +# -i input.mp4 - input file containing video and audio streams +# -map 0:2 - select stream index 2 from input 0 +# -c:a libmp3lame - use the LAME MP3 encoder for the audio stream +# -q:a 2 - set variable bitrate (VBR) audio quality level 2 +# (lower is better quality, typical range 0–9) +# out0.mp3 - output MP3 file containing the selected audio stream +ffmpeg -i .\input.mp4 -map 0:2 -c:a libmp3lame -q:a 2 out0.mp3 \ No newline at end of file From 08d95d4186710677ae5e3e3349f7926b8e8ab73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sun, 18 Jan 2026 16:54:35 +0100 Subject: [PATCH 41/41] Add script to create and manage an Azure VM with networking components --- azure/crate-azure-vm.ps1 | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 azure/crate-azure-vm.ps1 diff --git a/azure/crate-azure-vm.ps1 b/azure/crate-azure-vm.ps1 new file mode 100644 index 0000000..ea5f8a4 --- /dev/null +++ b/azure/crate-azure-vm.ps1 @@ -0,0 +1,71 @@ +# Azure VM Creation Script - Debian 11 +# This script creates a Debian 11 VM in Azure with a predefined network security group allowing SSH access. +# Prerequisites: +# - Azure CLI installed and logged in (`az login`) +# - A resource group named "Playground" with a network security group "ssh-common-ngs" allowing SSH on port 22. + +$SUBSCRIPTION_ID = '7f796072-6602-418a-8ba9-92ebc9a4797d' +$VM_NAME = 'vmDebian11' +$USER = 'alan' +$PASSWORD = 'F897cab3c9f1475d8a7ff96d549358f2.#1A' +$LOC = 'polandcentral' # `az account list-locations -o table` +$NGS = "/subscriptions/$SUBSCRIPTION_ID/resourcegroups/Playground/providers/Microsoft.Network/networkSecurityGroups/ssh-common-ngs" # Pre-created NSG with SSH allowed on port 22. +$RG = "playground-azure-vm-rg-001" + +az account set --subscription $SUBSCRIPTION_ID + +Write-Host "Deleting old resource group" -ForegroundColor Magenta +Start-Job -ScriptBlock { + az group delete -n "playground-azure-vm-rg-000" -y +} | Out-Null + +Write-Host "Creating resource group: $RG" -ForegroundColor Green +az group create -n $RG -l $LOC | Out-Null + +Write-Host "Creating VNet and Public IP in parallel" -ForegroundColor Green +$vnetJob = Start-Job { + az network vnet create ` + -g $using:RG ` + -n "$using:VM_NAME-vnet" ` + --address-prefix 10.0.0.0/16 ` + --subnet-name "$using:VM_NAME-subnet" ` + --subnet-prefix 10.0.0.0/24 | Out-Null +} + +$ipJob = Start-Job { + az network public-ip create ` + -g $using:RG ` + -n "$using:VM_NAME-pip" ` + --sku Standard ` + --allocation-method Static | Out-Null +} + +Wait-Job $vnetJob, $ipJob | Receive-Job + +Write-Host "Creating NIC" -ForegroundColor Green +az network nic create ` + -g $RG ` + -n "$VM_NAME-nic" ` + --vnet-name "$VM_NAME-vnet" ` + --subnet "$VM_NAME-subnet" ` + --public-ip-address "$VM_NAME-pip" ` + --network-security-group $NGS | Out-Null + +Write-Host "Creating VM" -ForegroundColor Green +az vm create ` + -g $RG ` + -n $VM_NAME ` + --nics "$VM_NAME-nic" ` + --image Debian11 ` + --admin-username $USER ` + --admin-password $PASSWORD ` + --size Standard_B1ms | Out-Null + +Write-Host "Done. You can connect to the VM using:" -ForegroundColor Green +$publicIP = az network public-ip show ` + -g $RG ` + -n "$VM_NAME-pip" ` + --query "ipAddress" ` + -o tsv + +ssh $USER@$publicIP -o StrictHostKeyChecking=no user@$publicIP \ No newline at end of file