Skip to content

Instantly share code, notes, and snippets.

View jaymecd's full-sized avatar

Nikolai Zujev jaymecd

View GitHub Profile
@jaymecd
jaymecd / An iTerm Profiles.md
Last active November 11, 2024 14:42
My iTerm profiles
  1. Download iTerm.profiles.json file file.
  2. Open iTerm.app
  3. Open app properties and go to Profiles
  4. Make backup of existing profiles you have: Other Actions > Save all profiles as JSON ...
  5. Load new profiles: Other Actions > Import JSON profiles ...
  6. Restart iTerm

Now you should have 2 profiles:

  • Default - default one, used to open standalone windows.
@jaymecd
jaymecd / signing-git-commits.md
Created April 29, 2022 11:35 — forked from phortuin/signing-git-commits.md
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
jaymecd / adventofcode_2021_05.py
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
jaymecd / adventofcode_2021_04.py
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(fp.read().splitlines(False))
class Num(int):
@jaymecd
jaymecd / auto_remount_noexec_volume.md
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

setup:

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 / 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")