Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / getMillis.ps1
Created February 20, 2021 02:17
Convert Unix Timestamp (with millisecond!) to Local time
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 February 24, 2021 03:49
Create Code Files, Test Files, and Link them
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
}
@pkutaj
pkutaj / refactoredNomad.ps1
Created February 24, 2021 09:56
refactoredNomad
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) {
@pkutaj
pkutaj / spagettiNomad.ps1
Last active February 24, 2021 09:57
spagettiNomad
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 March 12, 2021 04:17
PowerShell's script to validate / download OpenSSL certificate
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 September 16, 2021 06:21
Show Git Branches Which are local-only, remote-only or both
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 October 14, 2021 14:36
File Count per Folder in Powershell (not recursive)
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 November 27, 2021 08:44
powershell command for getting files in subfolders in a table with parent folder in another column
dir *.mp4 -rec -file |
select-object @{
Name="folder";
Expression = {Split-Path (Split-Path $_.Fullname -parent) -leaf}
},name
@pkutaj
pkutaj / Force-OutlookAddinLoad.ps1
Last active December 30, 2021 11:03
Force Load Outlook Addin
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 December 31, 2021 08:43
template for using Python's argparse module
#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")