Skip to content

Instantly share code, notes, and snippets.

View alimbada's full-sized avatar

Ammaar Limbada alimbada

View GitHub Profile
@alimbada
alimbada / keybindings.json
Last active May 23, 2024 15:18
VS Code Keybindings
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+left",
"command": "cursorWordPartLeft",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+left",
"command": "cursorWordPartLeftSelect",
@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"
}
@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