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 / searchWingetLogs.ps1
Last active August 21, 2023 18:11
PowerShell Core function to search Winget (aka Windows Package Manager) logs
#Requires -Version 6.0
<#
.SYNOPSIS
Retrieves recent winget logs and searches them for a pattern, if specified.
.DESCRIPTION
This script parses the Windows Package Manager winget command-line tool log files and allows searching by specifying a pattern or date boundaries.
.PARAMETER Search
The pattern to search for in the log files. If not specified, all log entries are returned.
.PARAMETER AfterDate
The date after which to search for log entries. If not specified, all log entries are returned.
@mavaddat
mavaddat / xmllistInstaller.ps1
Last active January 23, 2025 18:46
Download and install xmllint for Windows
#Requires -Modules PSParseHTML
function Install-XmlLint {
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$InstallPath = (Join-Path -Path "$env:LOCALAPPDATA\Programs" -ChildPath xmllint),
[switch]
$Force
)
@mavaddat
mavaddat / [MS-PSRP].pdf
Last active January 20, 2023 19:03
This is the schema for the CLIXML, which is used by PowerShell. Common Language Infrastructure (CLI) XML file with data that represents Microsoft .NET Framework objects and creates the PowerShell objects.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mavaddat
mavaddat / sortVSCodeSettings.ps1
Created January 19, 2023 13:35
A script to sort the VS Code settings JSON file by key.
Get-Content -Path "$env:APPDATA\Code - Insiders\User\settings.json" | ConvertFrom-Json -AsHashtable | ForEach-Object { $sortedSettings = [System.Collections.Generic.SortedDictionary[string,pscustomobject]]::new(); ($vsCodeSettings = $_) | Write-Output } | Select-Object -ExpandProperty Keys | ForEach-Object { $sortedSettings.Add($_,$vsCodeSettings[$_] )}
@mavaddat
mavaddat / substituteEnv.ps1
Created January 15, 2023 23:56
This snippet will substitute the environment variables into the VS Code settings.json file.
Get-Content -Path "$env:APPDATA\Code*\User\settings.json" | ForEach-Object -Begin { $pattern = '\$\{env:([^\}]+)\}'; } { $match = $_ | Select-String -Pattern $pattern; if ($null -ne $match) { $match = $match.Matches.Groups[1]; $match = (Get-Item -Path Env:\$match).Value -replace '\\', '\\'; $_ -replace $pattern, $match } else { $_ } } | Set-Content -Path ($temp = New-TemporaryFile) && Get-Content $temp | Set-Content -Path "$env:APPDATA\Code*\User\settings.json"
@mavaddat
mavaddat / stringsimilarity.js
Last active May 16, 2024 03:09
Approximate string distance using n-gram generic solution by MgSam on https://stackoverflow.com/a/62216738/1757756
"use strict";
function stringSimilarity(str1, str2, gramSize = 2) {
function getNGrams(s, len) {
s = ' '.repeat(len - 1) + s.toLowerCase() + ' '.repeat(len - 1);
let v = new Array(s.length - len + 1);
for (let i = 0; i < v.length; i++) {
v[i] = s.slice(i, i + len);
}
return v;
}
@mavaddat
mavaddat / clipboardHTML.ps1
Created January 11, 2023 05:00
Get Clipboard HTML
[System.Windows.Forms.Clipboard]::GetData("HTML Format") | ForEach-Object { $_ -replace '(?:<!--[^>]*-->|</?(html|body)>)' -split "`n"} | Select-Object -Skip 8 -First 1 | ForEach-Object { $_ -replace '<(\S+)[^>]*>','<$1>'} | Set-Clipboard
@mavaddat
mavaddat / download.sh
Last active December 25, 2022 23:49 — forked from mildred/download.sh
Download http://www.ghaemmagham.net/ from archive.org Wayback Machine
#!/bin/bash
url=http://www.ghaemmagham.net/
webarchive=https://web.archive.org
wget="wget -e robots=off -nv"
tab="$(printf '\t')"
additional_url=url.list
# Construct listing.txt from url.list
# The list of archived pages, including some wildcard url
@mavaddat
mavaddat / chesskidGold.js
Created November 30, 2022 08:14
Script to enable or disable gold memberships on a page of students on chesskid
// To disable gold memberships for all students on the current page, use the following two lines.
let disableGold = document.querySelectorAll("#app > div > main > section > div.body.empty > div.my-kids-list > div > div.list-item-info > div.user-info > div.user-tagline-info > a.membership-icon.icons-gold.remove-gold-membership-small.i-block.mright5")
disableGold.forEach(e=>{ setTimeout(e.click(),500) })
// To enable gold memberships for all students on the current page, use the following two lines.
let enableGold = document.querySelectorAll("#app > div > main > section > div.body.empty > div.my-kids-list > div > div.list-item-info > div.user-info > div.user-tagline-info > a.membership-icon.icons-gold.add-gold-membership-small.i-block.mright5")
enableGold.forEach(e=>{ setTimeout(e.click(),500) })
@mavaddat
mavaddat / extractBP.ps1
Last active November 28, 2022 01:41
Convert Blood Pressures from Google Fit Takeout Files to CSV
$TakeoutExtractedPath = "C:\Users\mavad\AppData\Local\Temp\MicrosoftEdgeDownloads\6acfbb86-1c53-4929-9741-118ff28d0db0\Takeout\Fit\All Data"
$UtcOffset = [System.TimeZone]::CurrentTimeZone.GetUtcOffset(0).Hours
(Get-ChildItem -Path $TakeoutExtractedPath -Filter *blood* -Recurse | ForEach-Object {
Get-Content -Path $_ | ConvertFrom-Json | Select-Object -ExpandProperty 'Data Points'
} | ForEach-Object {
[pscustomobject]@{
Date = [datetime]::UnixEpoch.AddMicroseconds(($_.endTimeNanos * 1E-3)).AddHours($UtcOffset)
Systolic = $_.fitValue.value.fpVal[0];
Diastolic = $_.fitValue.value.fpVal[1]
} | Write-Output