Skip to content

Instantly share code, notes, and snippets.

View alimbada's full-sized avatar

Ammaar Limbada alimbada

View GitHub Profile
nslookup myip.opendns.com resolver1.opendns.com
@alimbada
alimbada / Add-WslRoute.ps1
Created October 11, 2024 11:09
Add a route for WSL to connect to the Internet when connected to VPN using GlobalProtect
$wslAddress = wsl ip -4 a show eth0 | wsl grep -Po 'inet \K[0-9.]*'
# This assumes you only have one interface containing 'WSL' in its name
$ifId = (Get-NetIPInterface -InterfaceAlias "*WSL*" -AddressFamily IPv4).ifIndex
route add -p $wslAddress mask 255.255.255.255 $wslAddress metric 256 if $ifId
@alimbada
alimbada / Install-GitHubMsi.ps1
Last active December 12, 2024 18:43
Download and install the latest release of an app from a GitHub repo
$repo = $args[0];
$outdir = $args[1]
$release = (curl -s https://api.github.com/repos/scito/extract_otp_secrets/releases/latest | ConvertFrom-Json).assets | where { $_.name -like "*.msi" -or $_.name -like "*.exe" }
# TODO: check there's only one item
$outFile = "$outdir\$($release.name)";
curl -L $release.browser_download_url --output $outFile;
& $outFile
#Requires AutoHotkey v2.0
#SingleInstance
Run "powershell -NoExit C:\Users\Ammaar.Limbada\Register-KvmEvents.ps1", , "Hide"
Persistent
@alimbada
alimbada / Restart-Gpu.ps1
Created August 8, 2024 22:07
Restart GPU
# Use Get-PnpDevice with no parameters to get the name of the device
Get-PnpDevice -FriendlyName "AMD Radeon RX 6700" | Disable-PnpDevice -Confirm:$false ; Sleep -Seconds 5; Get-PnpDevice -FriendlyName "AMD Radeon RX 6700" | Enable-PnpDevice -Confirm:$false
@alimbada
alimbada / Register-KvmEvents.ps1
Last active August 30, 2024 14:08
Send commands for switching HDMI input to TV when WMI events are triggered by KVM switch (connect/disconnect)
Register-WmiEvent -Query "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'win32_PNPEntity' AND TargetInstance.DeviceID like 'USB\\VID_045B&PID_0209%'" -SourceIdentifier KVMConnected -Action { lgtv --name MyTV --ssl setInput HDMI_4 }
Register-WmiEvent -Query "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'win32_PNPEntity' AND TargetInstance.DeviceID like 'USB\\VID_045B&PID_0209%'" -SourceIdentifier KVMDisonnected -Action { lgtv --name MyTV --ssl setInput HDMI_3 }
@alimbada
alimbada / settings.json
Last active July 2, 2024 08:26
VS Code Settings
{
"[feature]": {
"editor.defaultFormatter": "alexkrechik.cucumberautocomplete"
},
"[java]": {
"editor.foldingImportsByDefault": true,
"editor.suggest.snippetsPreventQuickSuggestions": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
@alimbada
alimbada / keybindings.json
Last active June 4, 2024 16:48
VS Code Keybindings (mostly inspired by Visual Studio with ReSharper & IntelliJ IDEA)
// Place your key bindings in this file to override the defaultsauto[]
[
// CamelHumps words
{
"key": "ctrl+left",
"command": "cursorWordPartLeft",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+left",
@alimbada
alimbada / CleanUpGmail.gs
Created May 15, 2024 22:41
Google Apps Script for cleaning up Gmail
function cleanUpGmail() {
var queries = [
'from:(noreply@steampowered.com) in:inbox subject:(from your Steam wishlist on sale) older_than:7d',
'from:(no-reply@twitch.tv) in:inbox subject:(is live) older_than:1d',
'from:ebay.com subject:("is live!" OR "has been relisted") older_than:7d',
// Security alerts
'from:(no-reply@accounts.google.com) in:inbox subject:("Security alert" OR "New sign-in from") older_than:1m',
// 2FA
'from:(no-reply@email.gog.com) in:inbox older_than:1d subject:("two-step authentication" )'
]
$videoFileBaseNames = ls *.mkv | % { $_.BaseName } # adjust file as necessary
foreach ($baseName in $videoFileBaseNames)
{
$episode = $baseName.Split()[3] # adjust parsing of episode as necessary
$subfile = (ls *$episode*.srt)[0]
mv "$subfile" "$baseName.srt"
}