Skip to content

Instantly share code, notes, and snippets.


Nikolai Zujev jaymecd

View GitHub Profile
jaymecd /
Last active Oct 23, 2020
Bash CLI skeleton + debug reader
#!/usr/bin/env bash
#/ Sample command to perform update and query it's status
#/ Usage: <SCRIPT_NAME> [-h|--help] <command>
#/ Available commands are:
#/ one - perform some update, idempotent
#/ two - query status of update
jaymecd / main.go
Created Aug 18, 2020 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
View main.go
package main
import (
#!/usr/bin/env bash
# Split single S3 Inventory manifest into sequential subsets.
# Usage:
# $ env INVENTORY_BUCKET=my-inventory INVENTORY_PATH=sample-name ./
set -euo pipefail
jaymecd /
Created Jun 2, 2020
This JQ one-liner to pivot JSON data

Pivot JSON data

This one-liner pivots data from group>users or user>groups:

$ cat incoming.json \
  | jq 'map(. as $in | .users[] | . as $u | {user:$u, group:$}) | group_by(.user) | map({user:.[0].user, groups: map(.group)})'

jaymecd / Makefile
Last active Mar 18, 2020
Default Makefile with envvar guard
View Makefile
MAKEFLAGS += --warn-undefined-variables
SHELL := bash -o pipefail -c
.PHONY: help all deps build
guardEnvVar = $(if $(value $(1)),,$(error env $(1) not defined))
# Note: help extracts title from ## comment just above the target, builds target/title grid and prints it pretty.
## Show help
jaymecd /
Last active Feb 6, 2020
Golang Auto Build Versioning
go run -ldflags "-s \
  -X main.Version=1.0.2 \
  -X main.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` \
  -X main.GitHash=`git rev-parse HEAD`" \

Adopted from

jaymecd /
Last active Oct 17, 2019
Packer with WinRM over HTTPS

Way to build Windows STIG/CIS hardened AMI on AWS.

Problem is that WinRM Basic authentication is blocked by GroupPolicy.

Therefore it's required to setup WinRM over HTTPS.

jaymecd / invoke_via_winrm_https.ps1
Created Oct 16, 2019
Powershell: invoke command via winrm (NTLM over HTTPS)
View invoke_via_winrm_https.ps1
# TEST WinRM connect
$targetHost = 'localhost'
$username = 'Administrator'
$password = 'PASSWORD'
$secret = ConvertTo-SecureString -String $password -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secret
$option = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
jaymecd / time.ps1
Last active May 21, 2019
measure command time
View time.ps1
function time([scriptblock]$scriptblock) {
$sw = [Diagnostics.Stopwatch]::StartNew()
. $scriptblock
Write-Output ""
Write-Output " >> Execution time: $($sw.Elapsed)"
time { Install-Module -Name PSWindowsUpdate }
jaymecd /
Created May 15, 2019 — forked from Zearin/
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.

Q: How can I make a chain of function decorators in Python?

If you are not into long explanations, see [Paolo Bergantino’s answer][2].

You can’t perform that action at this time.