Skip to content

Instantly share code, notes, and snippets.

View aleksei140888's full-sized avatar
👾

Oleksii aleksei140888

👾
View GitHub Profile
@aleksei140888
aleksei140888 / aws_cognito_get_tokens.py
Created April 7, 2022 12:17
The script helps to change the password for the cognito user and get access, id and resfresh tokens for it. (Please allow ALLOW_USER_PASSWORD_AUTH and ALLOW_USER_SRP_AUTH for your app_client)
import boto3
import logging
import botocore
from typing import Optional
from botocore.exceptions import ClientError
AWS_ACCESS_KEY_ID = 'AKIAS7AVEMA4RPAVEMAA'
AWS_SECRET_ACCESS_KEY = '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'
@aleksei140888
aleksei140888 / sqlite_row_factory.py
Created August 6, 2022 20:24
Python SQLite - select dicts - row factory lambda
import sqlite
conn = sqlite3.connect(database='my_cool_db.sqlite3')
# conn.row_factory = sqlite3.Row # not the prettiest option
conn.row_factory = lambda c, r: dict([(col[0], r[idx]) for idx, col in enumerate(c.description)])
cursor = self.conn.cursor()
result = cursor.execute("SELECT * FROM test WHERE name='myname';")
@aleksei140888
aleksei140888 / django_debug_db_connections.py
Created September 11, 2022 18:49
Decorator to display the number of queries to the database and the execution time of Django function (I am not the author)
from django.db import connection, reset_queries
import time
import functools
def query_debugger(func):
@functools.wraps(func)
def inner_func(*args, **kwargs):
reset_queries()