Skip to content

Instantly share code, notes, and snippets.

View alimbada's full-sized avatar

Ammaar Limbada alimbada

View GitHub Profile
$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"
}
@alimbada
alimbada / configure-tv-input.sh
Created January 26, 2024 18:27
Configure the TV input type to "PC" using LGWebOSRemote
lgtv --name MyTV --ssl startApp com.webos.app.homeconnect && sleep 4 && \
lgtv --name MyTV --ssl sendButton up up right enter && sleep 2 && \
lgtv --name MyTV --ssl sendButton enter && sleep 2 && \
lgtv --name MyTV --ssl sendButton down down down left enter && sleep 2 && \ # number of `down`s here depends on the input ID; in this case I'm configuring HDMI 3
lgtv --name MyTV --ssl sendButton down down down down down down down down down enter && sleep 2 && \
lgtv --name MyTV --ssl sendButton up up up right enter && sleep 2 && \ # as noted above, number of `up`s here depends on input ID
lgtv --name MyTV --ssl sendButton exit
@alimbada
alimbada / find-excludedirname-execdir.sh
Last active August 18, 2023 10:41
Run a command on directories containing $file with exclusion for directories named $dir
find . -type d -name $dir -prune -o -name '$file' -execdir pwd \;
# Example: find . -type d -name node_modules -prune -o -name 'package.json' -execdir npm install \;
@alimbada
alimbada / lgtv_control.lua
Last active April 22, 2024 11:13
Hammerspoon script to set up hotkeys for controlling LG webOS TV input and on/off state
local lgtv_path = "~/opt/lgtv/bin/lgtv" -- Full path to lgtv executable
local tv_name = "MyTV" -- Name of your TV, set when you run `lgtv auth`
local lgtv_cmd = lgtv_path.." --name "..tv_name
local my_input = "HDMI_3"
local other_input = "HDMI_4"
function get_command(command)
command = lgtv_cmd.. " " ..command.. " --ssl"
return command
@alimbada
alimbada / lgtv-remote.ahk
Last active May 2, 2024 17:36
Use CapsLock-<Number> hotkey to switch HDMI inputs, Capslock-[=/-] to turn TV on/off
#Requires AutoHotkey v2.0
#SingleInstance
#HotIf GetKeyState("CapsLock")
{
1::
{
RunWait "lgtv --name MyTV --ssl setInput HDMI_3", , "Hide"
ToggleCapsLock()
}
@alimbada
alimbada / lgtv-volume-control.ahk
Last active May 2, 2024 17:36
Intercept keyboard volume control keys to control LG TV
#Requires AutoHotkey v2.0
#SingleInstance
Volume_Up::
{
audio_device := SoundGetName()
If InStr(audio_device, "LG TV SSCR2")
Run "lgtv --name MyTV --ssl volumeUp", , "Hide"
Else
@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]) }
# 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