Skip to content

Instantly share code, notes, and snippets.

View jaymecd's full-sized avatar

Nikolai Zujev jaymecd

View GitHub Profile
jaymecd /
Created April 29, 2022 11:35 — forked from phortuin/
Set up a GPG key for signing Git commits on MacOS (M1)

Based on this blogpost.

To sign Git commits, you need a gpg key. GPG stands for GNU Privacy Guard and is the de facto implementation of the OpenPGP message format. PGP stands for ‘Pretty Good Privacy’ and is a standard to sign and encrypt messages.

Setting up

Install with Homebrew:

$ brew install gpg
jaymecd /
Created December 5, 2021 16:24
adventofcode 2021 05
#!/usr/bin/env python3
from __future__ import annotations
import sys
from collections import Counter
from pathlib import Path
from typing import List, Mapping, NamedTuple, Sequence
import enum
jaymecd /
Created December 5, 2021 11:23
adventofcode 2021 day 04
#!/usr/bin/env python3
from pprint import pprint
from typing import List, NamedTuple, Optional
with open('data.txt') as fp:
lines = iter(
class Num(int):
jaymecd /
Last active November 10, 2021 12:42
auto remount noexec volume

start a contaniner:

$  docker run --rm -ti --privileged alpine:latest sh

next, run code within a container


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 /
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 /
Created February 12, 2021 21:51 — forked from rueycheng/
GNU Make cheatsheet
jaymecd /
Created January 1, 2021 01:03 — 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 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 /
Last active April 6, 2022 02:47
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