This one-liner pivots data from group>users
or user>groups
:
$ cat incoming.json \
| jq 'map(. as $in | .users[] | . as $u | {user:$u, group:$in.group}) | group_by(.user) | map({user:.[0].user, groups: map(.group)})'
[
{
#!/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 |
package main | |
import ( | |
"context" | |
"errors" | |
"fmt" | |
"os" | |
"os/signal" | |
"syscall" | |
"time" |
#!/usr/bin/env bash | |
# | |
# Split single S3 Inventory manifest into sequential subsets. | |
# | |
# Usage: | |
# $ env INVENTORY_BUCKET=my-inventory INVENTORY_PATH=sample-name ./s3.batch.operations.manifest.split.sh | |
# | |
set -euo pipefail |
MAKEFLAGS += --warn-undefined-variables | |
SHELL := bash -o pipefail -c | |
.DEFAULT_GOAL := help | |
.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 |
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.
# 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 |
function time([scriptblock]$scriptblock) { | |
$sw = [Diagnostics.Stopwatch]::StartNew() | |
. $scriptblock | |
$sw.Stop() | |
Write-Output "" | |
Write-Output " >> Execution time: $($sw.Elapsed)" | |
} | |
time { Install-Module -Name PSWindowsUpdate } |
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
const substr = (str, start = 0, length = str.length) => { | |
if (start === 0 && length === str.length) { | |
return str; | |
} | |
if (start > str.length || length <= 0) { | |
return ''; | |
} | |
const startIndex = (start < 0) ? Math.max(0, str.length - Math.abs(start)) : start; |