Skip to content

Instantly share code, notes, and snippets.

View rnag's full-sized avatar

Ritvik Nag rnag

View GitHub Profile
@rnag
rnag / perf-vs-apischema.py
Last active December 8, 2024 22:45
Dataclass Wizard vs. Other De/Serialization Libraries!
# pip install apischema
# pip install dataclass-wizard
from dataclasses import dataclass, field
from timeit import timeit
from uuid import UUID, uuid4
from apischema import deserialize, serialize
from dataclass_wizard import JSONWizard
@rnag
rnag / main.py
Created November 27, 2024 06:55
Python: Compare `to string` conversion performance
from timeit import timeit
from dataclass_wizard.utils.type_conv import as_str
n = 100_000
print('(int) as_str():'.ljust(25), timeit('x = 42; as_str(x)', globals=globals(), number=n))
print('(int) str():'.ljust(25), timeit('x = 42; str(x)', globals=globals(), number=n))
print('(int) empty_if_none():'.ljust(25), timeit("x = 42; '' if x is None else str(x)", globals=globals(), number=n))
'''
>tesla-inventory-price-scraper.py<
@Author: Maxwell Mowbray
@Email: mmowbray@mentlegen.com
@Date: April 2020
@Description:
This script scrapes Tesla's car inventory website and alerts the user if a car under a certain price appears.
It can easily be adapted to do other things with the results, such as alert you when a specific car with a specific trim/color/wheel size appears in inventory.
@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:
[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 / 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 / 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 / cleanupEmptyFolders.ts
Last active February 3, 2023 22:20 — forked from arnoson/cleanupEmptyFolders.js
ts/node: remove empty directories recursively. `exclude` is a list of directories to not traverse (optimization)
import { readdirSync, rmdirSync, statSync } from 'node:fs';
import { basename, join } from 'node:path';
export const cleanupEmptyFolders = (
folder: string,
exclude: string[] = ['node_modules']
) => {
if (!statSync(folder).isDirectory()) return;
const folderName = basename(folder);