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 / lgtv-control.ahk
Last active April 22, 2024 11:21
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 / lgtv-switch input.ahk
Last active April 22, 2024 11:20
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_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 / Export-Chocolatey.ps1
Last active April 21, 2024 11:39
Export installed Chocolatey packages as packages.config - thanks to Matty666
#Put this in Export-Chocolatey.ps1 file and run it:
#.\Export-Chocolatey.ps1 > packages.config
#You can install the packages using
#choco install packages.config -y
Write-Output "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Write-Output "<packages>"
choco list -lo -r -y | % { " <package id=`"$($_.SubString(0, $_.IndexOf("|")))`" version=`"$($_.SubString($_.IndexOf("|") + 1))`" />" }
Write-Output "</packages>"
@alimbada
alimbada / relayd-igmpproxy.sh
Created October 31, 2018 13:38 — forked from braian87b/relayd-igmpproxy.sh
How to setup Client Bridged / Client Mode / RelayD and IGMPProxy for OpenWRT / LEDE
# Client Bridged / Client Mode / RelayD and IGMPProxy (It works)
# RelayD is to redirect packages and IGMP is for redirect IGMP packages
# Our network is 192.168.1.0/24
# Steps:
# Configure WAN as static
# We should edit our wan iface and put static IP
uci set network.wan='interface'
uci set network.wan.proto='static'
uci set network.wan.ipaddr='192.168.1.239' # Main Network IP
@alimbada
alimbada / Wake.ps1
Last active February 8, 2024 21:03
PowerShell script for sending Wake On LAN magic packets to given machines/MAC address(es)
#######################################################
##
## Wake.ps1, v1.0, 2013
##
## Adapted by Ammaar Limbada
## Original Author: Matthijs ten Seldam, Microsoft (see: http://blogs.technet.com/matthts)
##
#######################################################
<#
@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 / gist:3083937
Created July 10, 2012 15:11
Metro Style for WPF Button
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style
x:Key="ButtonFocusVisual">
<Setter
Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2" />
</ControlTemplate>