Skip to content

Instantly share code, notes, and snippets.


Nikolai Zujev jaymecd

View GitHub Profile
jaymecd /
Created May 6, 2021
relative time in shell (awk)
#!/user/bin/env bash
# run as ./relative_time 2021-05-06T20:37:59Z
relative_time() {
declare -r dt="$1"
declare ts_then ts_now retval
! { ts1=$(date +%s -d "${dt}"); retval=$?; }
jaymecd /
Created Feb 12, 2021 — forked from rueycheng/
GNU Make cheatsheet
jaymecd /
Created Jan 1, 2021 — forked from jackiekazil/
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value

jaymecd /
Created Dec 28, 2020
parallel async python3 with timeout
#!/usr/bin/env python3
import asyncio
from typing import List, Awaitable
async def slow_job(delay: int):
print(f"running slow_job with {delay}s delay ...")
await asyncio.sleep(delay)
print(f"slow_job with {delay}s delay is done")
jaymecd /
Last active Nov 4, 2020
Bash CLI skeleton + debug reader
#!/usr/bin/env bash
#/ Sample command to perform update and query it's status
#/ Usage: <SELF_NAME> [-h|--help] <command>
#/ Available commands:
#/ one - perform some update, idempotent
#/ usage: <SELF_NAME> one <arg1> [arg2]
#/ 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 Jul 5, 2021
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.