Skip to content

Instantly share code, notes, and snippets.

View rnag's full-sized avatar

Ritvik Nag rnag

View GitHub Profile
@rnag
rnag / json_field_remapping.py
Last active April 6, 2024 11:37
field/key remapping
from dataclasses import dataclass
from .remappers import Alias, remapper # see module `remappers.py` below
@dataclass
class DiveSpot(metaclass=remapper):
id: str = Alias('_id')
name: str = Alias('divespot')
# stub to satisfy external linters and type checkers
@rnag
rnag / .Rewrite-Git-Commit-Author.md
Last active February 27, 2024 19:54
Git - Change Commit Author

Bash/Zsh Function to Change Author for Commit(s)

Based off my Answer on SO.


The below function cca (shorthand for change-commit-author) makes some assumptions:

  • The branch with commit(s) to update author for is the current branch.
  • Git User / Email (AKA New Author) is the one currently set up with git.
  • One of the following arguments is passed in:
@rnag
rnag / conftest.py
Last active February 17, 2024 09:09
pytest: mock builtin file open()
# Prerequisites:
# $ pip install pytest pytest-mock
from functools import cache
from unittest.mock import MagicMock, mock_open
import pytest
from pytest_mock import MockerFixture
[user]
name = Ritvik Nag
[init]
defaultBranch = main
[push]
followTags = true
autoSetupRemote = true
@rnag
rnag / .editorconfig
Created January 20, 2024 05:30
.editorconfig
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org
# top-most EditorConfig file
root = true
[*]
# Change these settings to your own preference
@rnag
rnag / a_instructions
Created January 19, 2024 02:05
VS Code (.vscode) - My Settings
Put below files in `.vscode` folder
@rnag
rnag / metaclasses.py
Last active September 10, 2023 00:14
Field Property Support in Dataclasses, for Python 3.7+
from __future__ import annotations
import builtins
from collections import deque
from dataclasses import field as dataclass_field, Field, MISSING
from logging import getLogger
log = getLogger(__name__)
@rnag
rnag / parameterStore.ts
Last active August 3, 2023 15:48 — forked from cbschuld/parameterStore.ts
Create or obtain values from the AWS Parameter store with Typescript/node
import { SSM } from 'aws-sdk';
/**
* Get the value for a parameter in SSM Parameter Store. By default, decrypt
* the value as we assume it is stored as a "SecretString"
*
* Ref: https://gist.github.com/cbschuld/938190f81d00934f7a158ff223fb5e02
*
* @param ssm The SSM client
* @param name Name of the parameter
@rnag
rnag / validate_test_1.py
Last active July 28, 2023 06:22
Dataclass Type Validation
# dataclass type validation for fields on class instantiation -and- on assignment.
from dataclasses import dataclass
from validators import TypeValidator
@dataclass
class FooDC:
# alternatively, like:
@rnag
rnag / my_stack.py
Last active May 18, 2023 02:35
AWS CDK - AWS Lambda Asset
# from pathlib import Path # Optional
# Using CDK v2
from aws_cdk import Duration
from aws_cdk.aws_lambda import Function, Runtime
from aws_cdk_lambda_asset.zip_asset_code import ZipAssetCode
# NOTE: Only example usage below (needs some modification)