Skip to content

Instantly share code, notes, and snippets.

View saswata-dutta's full-sized avatar
💭
I may be slow to respond.

Saswata Dutta saswata-dutta

💭
I may be slow to respond.
View GitHub Profile
@saswata-dutta
saswata-dutta / json_cleaner.py
Created April 13, 2024 14:48 — forked from pepoluan/json_cleaner.py
Python-based JSON Cleanup Preprocessor
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Context: https://stackoverflow.com/a/56701174/149900
from io import StringIO
WHITESPACE = " \t\r\n"
@saswata-dutta
saswata-dutta / cloud9.md
Created May 30, 2023 06:17 — forked from jamstooks/cloud9.md
Notes on starting up an AWS Cloud9 Django dev environment with Python3

My AWS Cloud9 Setup for Python/Django and Node

Getting setup

sudo yum -y update

I'm not a big fan of their default bash prompt:

echo "export PS1='[\D{%F %T}]\n\[\e]0;\w\a\]\[\e[32m\]\u:\[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bashrc

source ~/.bashrc

@saswata-dutta
saswata-dutta / Verify_Cognito_JWT_in_Ktor.md
Created February 5, 2023 05:58 — forked from saggie/Verify_Cognito_JWT_in_Ktor.md
Verify Amazon Cognito JWT in Ktor

(In Ktor: 1.6.2)

  • application.conf

    ...
    jwt {
        issuer = "https://cognito-idp.ap-northeast-1.amazonaws.com/__SPECIFY_POOL_ID_HERE__"
        audience = "__SPECIFY_CLIENT_ID_HERE__"
        realm = "ktor sample app"
    
@saswata-dutta
saswata-dutta / shardcalc.py
Created November 13, 2022 06:45 — forked from colmmacc/shardcalc.py
Calculate the blast radius of a shuffle shard
import sys
# choose() is the same as computing the number of combinations. Normally this is
# equal to:
#
# factorial(N) / (factorial(m) * factorial(N - m))
#
# but this is very slow to run and requires a deep stack (without tail
# recursion).
#
@saswata-dutta
saswata-dutta / get_lat_lon_exif_pil.py
Created September 30, 2022 03:13 — forked from erans/get_lat_lon_exif_pil.py
Get Latitude and Longitude from EXIF using PIL
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
@saswata-dutta
saswata-dutta / artillery-config.test.yaml
Created September 11, 2022 18:10 — forked from whitehorse0/artillery-config.test.yaml
Artillery configuration example Load testing, and allow writing custom logic JS functions to be called at certain points during the execution of a scenario.
config:
target: "http://localhost:8000"
http:
timeout: 10 # Responses have to be sent within 10 seconds or the request will be aborted
processor: "./processor.js"
phases:
# Create 100 virtual users every second for 60 seconds
- duration: 60 # seconds
arrivalRate: 100 # virtual users
@saswata-dutta
saswata-dutta / foobar.py
Created March 29, 2022 07:39 — forked from bhtucker/foobar.py
Sharing memory across uwsgi workers
"""
Simple worker showing different worker ids sharing/incrementing the same memory region
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191 --sharedarea 2
Then just keep refreshing localhost:9090
"""
import uwsgi
INT_ORDS = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@saswata-dutta
saswata-dutta / pyrasite-stacktrace-how-to.md
Created September 24, 2021 05:14 — forked from soxofaan/pyrasite-stacktrace-how-to.md
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running Python script

Sometimes a Python script will simply hang forever with no indication of what is going wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward.

Here's a way to see where the program is currently stuck, using pyrasite a tool for injecting code into running Python processes.

Install gdb and pyrasite

Install gdb.

# Credit for this: Nicholas Swift
# as found at https://medium.com/@nicholas.w.swift/easy-a-star-pathfinding-7e6689c7f7b2
from warnings import warn
import heapq
class Node:
"""
A node class for A* Pathfinding
"""