Skip to content

Instantly share code, notes, and snippets.

View hansgafriedzal's full-sized avatar

Hans hansgafriedzal

View GitHub Profile
$path = 'log.csv'
cat $path | select -First 1 > out.csv
cat $path | select -skip 1 | where {
$log = $_.Split(',')
$ts = [long] $log[0]
$elapsed = [long] $log[1]
Write-Progress -Activity $ts
$elapsed -gt 7000
} | tee -FilePath .\out.csv -Append

Remove domain from URL

=RIGHT(A1, LEN(A1) - SEARCH(CHAR(127), SUBSTITUTE(A1, "/", CHAR(127), 3)))
  • Input: https://gist.github.com/hello/world/
  • Output: hello/world

Description:

  1. SUBSITUTE() replaces the 3rd slash with a dummy i.e., NBSP (non-breaking space) which is the 127th character in the ANSI set.
  2. SEARCH() returns the location of the dummy.
cd ''
dir -File -Recurse | where Extension -eq .log | foreach {
Write-Progress $_.BaseName
$flag = $false
cat $_ | foreach {
$line = $_ | sls 'ERROR' -CaseSensitive
if ($line.count) {
Write-Host
$line.Line
cd ''
$noOfSubsequentLines = 10
dir -File -Recurse | where Extension -eq .log | foreach {
Write-Progress $_.BaseName
$lineCounter = 0
cat $_ | foreach {
$line = $null
$line = $_ | sls '1c8a58ca-ad9f-46e9-b307-92134222e03e'
if ($line.Count -gt 0) {
$ID = 'Sv3YrYFXOWU'
yt-dlp $ID -f bestvideo --output '%(id)s.%(ext)s'
$START='00:00:07.000' # start 4 seconds in
$LENGTH='00:00:33.000' # end after 5 seconds
$SIZE='960x540' # size of the output GIF
ffmpeg -ss $START -i "$ID.mp4" -pix_fmt rgb24 -r 10 -s $SIZE -t $LENGTH $ID-unoptimized.gif -y
function gcd ($a, $b) {
if ($b -gt $a)
{
$a, $b = $b, $a
}
Write-Host ">$a, $b"
if ($b -eq 0)
{
return $a
@hansgafriedzal
hansgafriedzal / Upgrade-PipPackages.ps1
Last active July 13, 2023 05:07
upgrade all pip packages
function Upgrade-PipPackages
{
pip freeze > requirements.txt
(cat .\requirements.txt) -replace '==', '>=' >> requirements.txt
pip install -r requirements.txt --upgrade
del requirements.txt
}
dir $PSScriptRoot\*\Subs | foreach {
$_.Parent.FullName
$movieDir = $_.Parent.FullName
cd $movieDir
$movieFileName = dir *.mkv, *.mp4, *.avi | select -ExpandProperty BaseName -First 1
cd $_
dir *.srt | where BaseName -like *english* | sort Length -Descending | select -First 1 | foreach {
$newSub = $movieFileName + '.en' + $_.Extension
function tgit ($Command, $Path) {
$cmd = 'TortoiseGitProc.exe /command:' + $Command
if ($Path) {
$cmd += ' /path:' + (dir -LiteralPath $Path)
}
& cmd /c "$cmd 2>&1"
}
$timestamp = Get-Date -format "yyyyMMddHHmmss"
Get-MgUser -All `
-Filter 'accountEnabled eq true' `
-Property AccountEnabled, OnPremisesUserPrincipalName, UserPrincipalName, DisplayName, CompanyName, UserId `
-ExpandProperty Manager | foreach{
[pscustomobject] @{
Id = $_.Id
UserPrincipalName = $_.UserPrincipalName
DisplayName = $_.DisplayName