Skip to content

Instantly share code, notes, and snippets.

View rnag's full-sized avatar

Ritvik Nag rnag

View GitHub Profile
@rnag
rnag / ts-compile.ts
Last active February 3, 2023 22:33
TypeScript Compiler API - Example
// TypeScript code to programatically run the equivalent of `tsc`
//
// With Slight modifications, such as *Colorized* output being displayed.
//
// However, the nice one-line Error Summary that `tsc` gives you (e.g. Errors in X files) is currently missing.
//
// Refs:
// - https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md
// - https://github.com/Microsoft/TypeScript/issues/6387#issuecomment-169739615
@rnag
rnag / .bashrc
Last active April 2, 2023 23:07 — forked from Frechet/git repush tag
# delete and re-create the latest tag on remote
rmtag () {
export TAG=$(git describe --tags --abbrev=0)
git tag -d $TAG
git tag $TAG
git push origin :$TAG
git push origin $TAG
}
@rnag
rnag / Dockerfile
Last active April 2, 2023 23:35
Dockerfile for `rembg-aws-lambda` in AWS environments
# Note:
# Lock in build date on the tag (ex: 2023.03.29) - otherwise, we rebuild the
# entire Docker image each time a tag is updated (ex: python:3.9-x86_64)
#
# Refs:
# - https://github.com/peterheb/rembg-lambda/issues/1#issue-1621934443
# - https://docs.aws.amazon.com/lambda/latest/dg/python-image.html
# - https://gallery.ecr.aws/lambda/python (-> Image tags)
# Date (Timestamp) of the Image to Build
@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)
@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 / 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 / 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 / a_instructions
Created January 19, 2024 02:05
VS Code (.vscode) - My Settings
Put below files in `.vscode` folder
@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
[user]
name = Ritvik Nag
[init]
defaultBranch = main
[push]
followTags = true
autoSetupRemote = true