Skip to content

Instantly share code, notes, and snippets.

View jaymecd's full-sized avatar

Nikolai Zujev jaymecd

View GitHub Profile
from __future__ import annotations
import boto3
from functools import lru_cache
import dataclasses as dc
import uuid
def _reconstruct_params(cls, params: dict) -> dict:
if not hasattr(cls, '__dc_field_names'):
@jaymecd
jaymecd / relative_time.sh
Created May 6, 2021 21:18
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
jaymecd / BashPrompt.md
Last active April 7, 2021 03:54
PS1 bash prompt with git info

Dynamic bash prompt and alias list

$ curl -sSL https://gist.github.com/jaymecd/6887829/raw/bash_prompt | sudo tee /etc/bash_prompt

$ curl -sSL https://gist.github.com/jaymecd/6887829/raw/bash_alias | sudo tee /etc/bash_alias

$ curl -sSL https://gist.github.com/jaymecd/6887829/raw/bashrc | tee -a ~/.bashrc
@jaymecd
jaymecd / GNU-Make.md
Created February 12, 2021 21:51 — forked from rueycheng/GNU-Make.md
GNU Make cheatsheet
@jaymecd
jaymecd / rounding_decimals.md
Created January 1, 2021 01:03 — forked from jackiekazil/rounding_decimals.md
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
jaymecd / parallel_async_python3_with_timeout.py
Created December 28, 2020 12:55
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
jaymecd / main.go
Created August 18, 2020 19:03 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
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
@jaymecd
jaymecd / Makefile
Last active March 18, 2020 11:38
Default Makefile with envvar guard
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 / invoke_via_winrm_https.ps1
Created October 16, 2019 08:55
Powershell: invoke command via winrm (NTLM 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