Skip to content

Instantly share code, notes, and snippets.

View alimbada's full-sized avatar

Ammaar Limbada alimbada

View GitHub Profile
@alimbada
alimbada / Export-WindowsFeatures.ps1
Last active April 25, 2023 02:13
Export installed Windows features as chocolatey script
dism /online /Get-Features /Format:Table | Select-String Enabled | % {($_ -split '\|', 2)[0].Trim()} | % { "choco install $_ -source windowsfeatures" }
@alimbada
alimbada / Get-StaleFirewallRules.ps1
Created February 22, 2023 12:49
Use PowerShell to get Windows firewall rules for applications that are no longer installed.
Get-NetFirewallRule | where { $_.Name -Like "*.exe" -and -not(Test-Path -Path $_.Name.Split('}')[1]) }
@alimbada
alimbada / NuGetSolutionWideDownGrade.ps1
Created December 5, 2013 12:59
Commands for downgrading NuGet packages across a solution in Visual Studio using the Package Manager Console
$projects =Get-Project -All | Select @{ Name=”ProjectName”;Expression={$_.ProjectName}}, @{Name=”Has”;Expression={Get-Package $PackageName -Project $_.Name}} | where { $_.Has -and $_.Has.ToString() -eq '$PackageName $CurrentPackageVersion' }
$projects | select { Uninstall-Package $PackageName -ProjectName $_.ProjectName -Force }
$projects | select { Install-Package $PackageName -Version $PackageVersionToDowngradeTo -ProjectName $_.ProjectName }
@alimbada
alimbada / mkv-extract-subtitles.sh
Last active April 29, 2022 07:07
Use mkvextract to extract subtitles from a directory of MKV files into SRT files
# Subtitle track number is usually the same for a whole series and usually for all encodes from a specific place
# Use this first to ascertain the track number
# find . -iname '*.mkv' -maxdepth 1 -exec sh -c "ffprobe -hide_banner -i '{}' 2>&1 | grep Subtitle | cut -d':' -f2 | cut -d'(' -f1 " \;
find . -iname '*.mkv' -maxdepth 1 -exec basename {} .mkv \; | xargs -I {} mkvextract tracks '{}.mkv' ${SUBTITLE_TRACK_NUMBER}:'{}.srt'
# get processes by memory usage on busybox
ps | tail -n +2 | awk 'BEGIN {OFS="\t"}; { s = ""; for (i = 5; i <= NF; i++) s = s $i " "; print $3, s }' | sort -rnk 1
@alimbada
alimbada / update_cloudflare_com_v4.sh
Created August 16, 2021 15:34
Modified Cloudflare DDNS update script for OpenWRT 15.05
#!/bin/sh
#
#.Distributed under the terms of the GNU General Public License (GPL) version 2.0
#
# script for sending updates to cloudflare.com
#.based on Ben Kulbertis cloudflare-update-record.sh found at http://gist.github.com/benkulbertis
#.and on George Johnson's cf-ddns.sh found at https://github.com/gstuartj/cf-ddns.sh
#.2016-2017 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
# CloudFlare API documentation at https://api.cloudflare.com/
#
@alimbada
alimbada / ChocoOutdatedTable.ps1
Created April 1, 2021 13:39
Formats the output of `choco outdated` into a more readable table
choco outdated -r | ConvertFrom-Csv -Delimiter '|' -Header 'Package name', 'Current version', 'Available version', 'Pinned?' | Format-Table
@alimbada
alimbada / plusnet-hub-reboot.sh
Last active March 16, 2021 09:52
Reboots Plusnet Hub One
#!/bin/sh
# Reboots Plusnet Hub One
routerip="192.168.1.254"
pass="<PASSWORD>"
# Call index page, store the output, then parse out whatever is needed
page=$(curl -Ls "http://$routerip/index.cgi?active_page=9148" -H 'Cookie: rg_cookie_session_id=' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'DNT: 1' --data 'active_page=9121' --cookie-jar cookies.txt)
posttoken=$(echo $page |grep post_token |awk 'BEGIN { FS = "\"post_token\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
requestid=$(echo $page |grep request_id |awk 'BEGIN { FS = "\"request_id\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
@alimbada
alimbada / revert-typechanges.sh
Created February 19, 2020 11:51
Revert git typechanges
git status --porcelain=2 | awk '{if($2==".T") {print "git checkout " $NF}}' | sh
@alimbada
alimbada / Kill App Scheduled Task.xml
Last active September 30, 2019 11:52
Scheduled Task for Reacting to Process Creation Event
<?xml version="1.0" encoding="UTF-16"?>
<!--
Pre-requisites: (see https://superuser.com/questions/745318/how-to-start-a-program-when-another-one-is-started)
Start and enter secpol.msc into the Run box
Navigate to Local Policies/Audit Policy
Double Click Audit process tracking and enable Success
-->
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2019-09-30T12:39:02.4100122</Date>