Skip to content

Instantly share code, notes, and snippets.

View mavaddat's full-sized avatar
🏠
Working from home

Mavaddat Javid mavaddat

🏠
Working from home
View GitHub Profile
@mavaddat
mavaddat / compileRun.ps1
Created July 10, 2020 23:17
Automatically compile and run the latest java file.
$curr = Get-Location
Get-ChildItem -Recurse | Sort-Object LastWriteTime -Descending | ForEach-Object {
Set-Location "$($_.FullName)/../"
if ((Select-String -Path $($_.FullName) -Pattern "\s*public static void main\(String\[\]\s*args\)") -and (Get-Command "javac" -ErrorAction Ignore) -and (Get-Command "java" -ErrorAction Ignore)) {
$compileOutput = &javac $_ 2>&1 | Out-String -Stream
if ($?) {
&"java" "$($_.Name -replace "\..+",'')"
}
foreach ($outMessage in $compileOutput) {
Write-Host $out
@mavaddat
mavaddat / Data validation.EXCEL.yaml
Created August 7, 2020 07:07
Sets data validation rules on ranges, prompts users to enter valid data, and displays messages when invalid data is entered.
name: Data validation
description: >-
Sets data validation rules on ranges, prompts users to enter valid data, and
displays messages when invalid data is entered.
host: EXCEL
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
$("#positive-number").click(() => tryCatch(addPositiveNumberRequirement));
@mavaddat
mavaddat / wifiPassword.ps1
Last active October 31, 2020 20:14
Get Windows 10 stored WiFi password using PowerShell 5.1 🖥
# Get current Wifi SSID
$ssid = $(netsh wlan show interfaces | Select-String -Pattern ".*Profile\s+:\s*(.*?)(?: \d+)?\s*$").Matches.Groups[1].Value
# Get Wifi key and set it to clipboard
$( &netsh.exe @("wlan", "show", "profile", "$ssid", "key=clear") | Select-String -Pattern ".*?key content\s+:\s*(.*)$").Matches.Groups[1].Value | Set-Clipboard
@mavaddat
mavaddat / Get-OfficeVersion.ps1
Created August 13, 2020 00:02
Show the version of Microsoft Office
$office = (Get-ChildItem 'HKLM:\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' | where -FilterScript { $_.GetValue("InstallLocation") -ccontains "C:\Program Files\Microsoft Office" } )
$office.GetValue("DisplayName"); $office.GetValue("DisplayVersion")
@mavaddat
mavaddat / horline.py
Last active March 30, 2021 03:03
Creates and prints a coloured horizontal line in bash output
class Bcolors:
def __init__(self):
self.HEADER = '\033[95m'
self.OKBLUE = '\033[94m'
self.OKGREEN = '\033[92m'
self.WARNING = '\033[93m'
self.FAIL = '\033[91m'
self.ENDC = '\033[0m'
self.BOLD = '\033[1m'
self.UNDERLINE = '\033[4m'
@mavaddat
mavaddat / Search.WORD.yaml
Created September 13, 2020 20:32
Shows basic and advanced search capabilities.
name: Search
description: Shows basic and advanced search capabilities.
host: WORD
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
$("#basic-search").click(() => tryCatch(basicSearch));
$("#wildcard-search").click(() => tryCatch(wildcardSearch));
@mavaddat
mavaddat / updateJDK.ps1
Last active August 4, 2021 00:24
Automated update of JDK path for AdoptOpenJDK triggered by update in Chocolatey. PowerShell directives are provided to the VBS Windows Script Host as encoded commands so as to avoid a shell screen popping up on trigger.
# This contains two lines (#4, #7) which will be run as an encoded PowerShell command inside a Visual Basic Script (VBScript) scheduled task below.
# Check if 'updateJDK.vbs' is already running in another process; if so, let's quit and just let that finish the task
Get-Process -Name '*WScript*' | foreach{if($_.CommandLine -imatch 'updateJDK.vbs' -and $_.Id -ne $PID){ exit } }
# We will update the %JAVA_HOME% path upon observing discrepency between the newest available JDK (local directory) and the %JAVA_HOME%
$jdk = Get-ChildItem (Resolve-Path 'C:\Program Files\AdoptOpenJDK\') -Depth 0 -Directory | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1; if(($null -ne ([System.Environment]::GetEnvironmentVariable('JAVA_HOME'))) -and ($env:JAVA_HOME -ne $jdk)) { [System.Environment]::SetEnvironmentVariable('JAVA_HOME',$($jdk.FullName),[System.EnvironmentVariableTarget]::User) }
# Whenever we change the script (i.e., the above line of PowerShell commands), we generate the new encoded command
@mavaddat
mavaddat / GPG_noninteractive_batch_sign_trust_and_send_gnupg_keys.md
Last active June 11, 2023 05:45
A script to search every contact in CSV file for publicly listed PGP or GPG key
Get-ChildItem -Recurse -File -include @('*.mov','*.mp4','*.mp2')| Where-Object -Property Length -GT 100Mb | foreach{
$curDuration = 0
$file = $_
Push-Location (Resolve-Path $file.PSParentPath -Relative)
$duration = [double](ffprobe -i "$($file.FullName)" -show_entries format=duration -v quiet -of default=noprint_wrappers=1:nokey=1)
for($i=0;$curDuration -lt $duration; $i++) {
$nextFileName = $file.BaseName + "-" + "$i"+$file.Extension
$args = "-ss $curDuration -i $($file.Name) -fs $(100Mb) $nextFileName"
Write-Host "ffmpeg $args"; pause;
Start-Process -FilePath (Resolve-Path (which ffmpeg)) -ArgumentList $args -WorkingDirectory $PWD -NoNewWindow -PassThru -Wait;
@mavaddat
mavaddat / resetPythonVSCode.ps1
Last active April 16, 2021 02:03
Hard reset vscode-python extension for VS Code
$pyExts = @() # Python extensions in VS Code array of strings scoped variable to be accessible outside the foreach context below
# Below, we get the `cmd` for VS Code in a flexible way
# Stable VS Code uses `code.cmd`
# Insider VS Code uses `code-insider.cmd`
# Thus, Stable and Insider editions use the pattern `code*cmd`
Get-Command -Name code*cmd -CommandType Application | ForEach-Object {
$vscode = $_
# Let's be sure VS Code isn't running
if ($null -ne ($VSCodeProcs = &$vscode --status | Select-String -Pattern '(?<cpu>\d+)\s+(?<mem>\d+)\s+(?<pid>\d+).+main' -AllMatches)){
# Use `taskkill` to gently request that VS Code terminate gracefully (as opposed to violently killing the process using the `Stop-Process` cmdlet)