Skip to content

Instantly share code, notes, and snippets.

View rnag's full-sized avatar

Ritvik Nag rnag

View GitHub Profile
@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 / .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 / 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);
@rnag
rnag / main.py
Last active August 25, 2022 20:58
dataclass re-decoration timing
# See comment below for an explanation of what this script is testing!
from dataclasses import dataclass, is_dataclass
from timeit import timeit
@dataclass
class A:
a: int = 10
@rnag
rnag / dump_json_to_term.py
Created August 23, 2022 14:11
measuring dump JSON to terminal times
from timeit import timeit
data = [
{
"eventStatus": "Failure",
"eventType": "Archive",
"objectName": "W12 BO Template",
"time": "2022-08-23T10:09:33.092Z"
},
{
@rnag
rnag / Dockerfile
Last active August 17, 2022 22:14
Python 3.9 Dockerfile using a Private PyPI Repository
# Ref:
# - https://pythonspeed.com/articles/base-image-python-docker-images/
# - https://github.com/FNNDSC/ubuntu-python3/blob/master/Dockerfile
#
# This Docker image uses the `ubuntu` base image for a slight performance
# improvement as mentioned in the article. At build time, you'll need to pass
# in the PyPI authentication info, as shown below:
#
# docker build -t ${image_tag_name} \
# --build-arg PYPI_URL=${PYPI_URL} \
@rnag
rnag / trim_space.py
Last active April 14, 2022 14:42
trim_extra_whitespace_times
import re
import string
from time import time
def main():
# Rust version run with `--release` (for reference), using `only_one_string` from here:
# https://stackoverflow.com/a/71864244/10237506
# trim_whitespace: 30ms
@rnag
rnag / config.toml
Last active April 8, 2022 22:26
~/.cargo/config.toml
[alias]
d = "doc --no-deps --open"
rr = "run --release"
@rnag
rnag / jest.config.js
Created January 7, 2022 15:51
jest config
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
// Added so that jest prefer to run tests on files
// with the *.ts extension instead (see below).
// https://stackoverflow.com/a/50145833/10237506