Skip to content

Instantly share code, notes, and snippets.

Nikolai Zujev jaymecd

Block or report user

Report or block jaymecd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jaymecd
jaymecd / a_json_data_pivot_with_jq.md
Created Jun 2, 2020
This JQ one-liner to pivot JSON data
View a_json_data_pivot_with_jq.md

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:$in.group}) | group_by(.user) | map({user:.[0].user, groups: map(.group)})'

[
  {
@jaymecd
jaymecd / Makefile
Last active Mar 18, 2020
Default Makefile with envvar guard
View Makefile
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
@jaymecd
jaymecd / build_stig_windows_with_packer.md
Last active Oct 17, 2019
Packer with WinRM over HTTPS
View build_stig_windows_with_packer.md

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
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
jaymecd / time.ps1
Last active May 21, 2019
measure command time
View time.ps1
function time([scriptblock]$scriptblock) {
$sw = [Diagnostics.Stopwatch]::StartNew()
. $scriptblock
$sw.Stop()
Write-Output ""
Write-Output " >> Execution time: $($sw.Elapsed)"
}
time { Install-Module -Name PSWindowsUpdate }
@jaymecd
jaymecd / python_decorator_guide.md
Created May 15, 2019 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)
View python_decorator_guide.md

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].

@jaymecd
jaymecd / substr.js
Last active May 12, 2019
ES6 training
View substr.js
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;
@jaymecd
jaymecd / python-logging.md
Created May 8, 2019 — forked from mariocj89/python-logging.md
Understanding logging in Python
View python-logging.md

Logging trees

Introduction

When applications are running in production, they become black boxes that need to be traced and monitored. One of the simplest, yet main, ways to do so is logging. Logging allows us - at the time we develop our software - to instruct the program to emit information while the system is running that will be useful for us and our sysadmins.

@jaymecd
jaymecd / cf_create_or_update.py
Created Apr 3, 2019 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
View cf_create_or_update.py
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore
@jaymecd
jaymecd / amend-git-author.md
Created Dec 3, 2018
Amend GIT author within branch starting from COMMIT_ID
View amend-git-author.md

To reset commit author its required:

  1. to update default user name/email. (--global could added)
$ git config user.name example user
$ git config user.email example@email.com
  1. set checkpoint to keep orignal commit tree.
You can’t perform that action at this time.