Skip to content

Instantly share code, notes, and snippets.

import asyncio
import time
from pathlib import Path
from uuid import uuid4
import os
import gc
from aiofile import AIOFile
from aiofiles import open as aio_open
from anyio import open_file as anyio_open
SRC_PATH = "../backend"
ENV_PATH = "../backend/.env.loc"
import redis
import random
import pickle
import pprint
import zlib
import os
@vncsna
vncsna / runbg.sh
Created October 22, 2024 17:33
Run command in the background
alias run='nohup "$@" > /dev/null 2>&1 &'
@vncsna
vncsna / source-poetry-env.sh
Last active November 11, 2024 15:33
Source one of the available environments
alias pe='source $(ls ~/.cache/pypoetry/virtualenvs | fzf | xargs -I {} echo ~/.cache/pypoetry/virtualenvs/{}/bin/activate)'
@vncsna
vncsna / unselect.js
Last active December 9, 2024 16:45
unselect_pull_request_files.js
// Unselect all
document.getElementsByName("viewed").forEach(ch => {if(ch.checked) {ch.click()}})
// Select some with "key"
document.getElementsByName("viewed").forEach(ch => { if (!ch.checked && ch.id.includes("key")) { ch.click(); } });
@vncsna
vncsna / db_manager.py
Created September 25, 2024 16:29 — forked from nitred/db_manager.py
Creating thread safe and managed sessions using SQLAlchemy
"""Creating thread safe and managed sessions using SQLAlchemy.
The sessions that are created are expected to be:
- thread safe
- handle committing
- handle rolling back on errors
- handle session removal/releasing once context or thread is closed.
Author: Nitish Reddy Koripalli
License: MIT
@vncsna
vncsna / save_aws_logs_to_postgresql.py
Last active November 19, 2024 21:52
Save aws logs to postgresql
import subprocess
import IPython
import psycopg2
def main(log_group):
def process_log_entry(timestamp, log_group, log_entry):
cursor.execute(
"INSERT INTO cloudwatch_logs (timestamp, log_group, log_entry) VALUES (%s, %s, %s)",
(timestamp, log_group, log_entry)
@vncsna
vncsna / save_aws_logs_to_duckdb.py
Last active November 19, 2024 21:51
Save aws logs to a duckdb
import subprocess
import IPython
import duckdb
def main(log_group):
def process_log_entry(timestamp, log_group, log_entry):
conn.execute(
"INSERT INTO cloudwatch_logs (timestamp, log_group, log_entry) VALUES (?, ?, ?)",
[timestamp, log_group, log_entry],
)
@vncsna
vncsna / find-icon.sh
Last active February 3, 2024 14:13
Find icons by name in linux
#!/bin/bash
icon_name="$1"
icon_directory="/usr/share/icons"
find "$icon_directory" -name "*$icon_name*"
@vncsna
vncsna / postgresql_indexes.sql
Created January 10, 2024 13:58
PostgreSQL Size of Indexes
-- Reference
-- https://stackoverflow.com/questions/46470030/postgresql-index-size-and-value-number
SELECT
i.relname "Table Name"
, indexrelname "Index Name"
, pg_size_pretty(pg_total_relation_size(relid)) As "Total Size"
, pg_size_pretty(pg_indexes_size(relid)) as "Total Size of all Indexes"
, pg_size_pretty(pg_relation_size(relid)) as "Table Size"
, pg_size_pretty(pg_relation_size(indexrelid)) "Index Size"