Skip to content

Instantly share code, notes, and snippets.

Avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / getMillis.ps1
Created Feb 20, 2021
Convert Unix Timestamp (with millisecond!) to Local time
View getMillis.ps1
function getMillis {
param (
$unixTimeStamp
)
$epochStart = Get-Date 01.01.1970
$millisStamp = ($epochStart + ([System.TimeSpan]::frommilliseconds($unixTimeStamp))).ToLocalTime()
$millisStampOutput = $millisStamp.ToString("yyyy-MM-dd HH:mm:ss.ffffff")
$millisStampClipboard = $millisStamp.ToString("HH:mm:ss.ffffff")
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Write-Host "Datetime: $millisStampOutput" -ForegroundColor Cyan
@pkutaj
pkutaj / create-codeFiles.ps1
Last active Feb 24, 2021
Create Code Files, Test Files, and Link them
View create-codeFiles.ps1
function create-codeFiles($name, $testName, $extension, $linkText) {
$codeFile = ("$name" -replace "\s", "_") -replace ".+", "$&.$extension"
$testFile = ("$name" -replace "\s", "_") -replace ".+", "$&$testName.$extension"
New-Item $codeFile -ErrorAction Ignore
New-Item $testFile -ErrorAction Ignore
Add-Content $testFile -Value $linkText
code .
Invoke-Item $codeFile
Invoke-Item $testFile
}
View refactoredNomad.ps1
function get-nomadLogs ([string]$jobId, [string]$featureFlag) {
function get-stderr ($jobId) {
$nomadLogs = nomad alloc logs -stderr -job $jobId
if (nomad status $jobID | Select-String status.*dead) {
Out-Host -InputObject $nomadLogs
}
}
function get-logs($jobId) {
View spagettiNomad.ps1
function get-nomadLogs ($jobId, $featureFlag) {
$nomadLogs = ($featureFlag -ne "e") ?
(nomad alloc logs -job $jobId) :
(nomad alloc logs -stderr -job $jobId)
if ($featureFlag -eq "l") { oh -InputObject $nomadLogs }
if (nomad status $jobID | sls -Pattern "(?=.*\d)failed") {
write-host "Job Failed - see webUI - stderr below" -ForegroundColor DarkRed
@pkutaj
pkutaj / downloadCert.ps1
Created Mar 12, 2021
PowerShell's script to validate / download OpenSSL certificate
View downloadCert.ps1
function test-certificate($domain, $contextLength = 10, [switch]$download) {
$cacertPath = "c:\cacert.pem"
$connectDomain = $domain + ":443"
#<feature> download certificate into a download folder
if($download) {
echo "q" | openssl s_client -servername $domain -connect $connectDomain -CAfile $cacertPath |
openssl x509 -text |
out-file "C:\Users\$env:USERNAME\downloads\$domain.txt" -force
Write-Host "~~~" -ForegroundColor darkcyan
@pkutaj
pkutaj / match-branches.ps1
Created Sep 16, 2021
Show Git Branches Which are local-only, remote-only or both
View match-branches.ps1
function match-branch ([switch]$local_only, [switch]$remote_only, [switch]$both) {
$localBranches = ((git branch -l) -replace "\*", "") -replace " ", ""
$remoteBranches = (((git branch -r) -replace "\*", "") -replace " ", "") -replace "origin/", ""
$branch_comparison = Compare-Object -ReferenceObject $localBranches -DifferenceObject $remoteBranches -IncludeEqual
| Select-Object @{Label = "branch"; Expression = { $_.InputObject } },
@{Label = ”both”; Expression = { $_.SideIndicator -eq "==" } },
@{Label = ”remote_only”; Expression = { $_.SideIndicator -eq "=>" } },
@{Label = ”local_only”; Expression = { $_.SideIndicator -eq "<=" } }
if ($local_only) { $branch_comparison | Where-Object -Property "local_only" -EQ "true" | Select-Object branch }
elseif ($remote_only) {$branch_comparison | Where-Object -Property "remote_only" -EQ "true" | Select-Object branch}
@pkutaj
pkutaj / filecount-per-folder.ps1
Last active Oct 14, 2021
File Count per Folder in Powershell (not recursive)
View filecount-per-folder.ps1
Get-ChildItem -Recurse -Directory |
Select-Object Name, @{
Name="FileCount";
Expression={(Get-ChildItem $_ -File | Measure-Object).Count }
}
@pkutaj
pkutaj / get_files_with_parent_folder.ps1
Last active Nov 27, 2021
powershell command for getting files in subfolders in a table with parent folder in another column
View get_files_with_parent_folder.ps1
dir *.mp4 -rec -file |
select-object @{
Name="folder";
Expression = {Split-Path (Split-Path $_.Fullname -parent) -leaf}
},name
@pkutaj
pkutaj / Force-OutlookAddinLoad.ps1
Last active Dec 30, 2021
Force Load Outlook Addin
View Force-OutlookAddinLoad.ps1
function disableResiliency {
param(
[Parameter(Mandatory = $true)]
[string]$AddinName,
[Parameter(Mandatory = $false)]
[switch]$Force,
[Parameter(Mandatory = $false)]
[switch]$AllowUserControl
)
$AddinList = $null
@pkutaj
pkutaj / argparse_boilerplate.py
Last active Dec 31, 2021
template for using Python's argparse module
View argparse_boilerplate.py
#file: foobar.py
import argparse
def function_proper(param1, param2) -> None:
#CODE...
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("--param1")
parser.add_argument("--param2")