Skip to content

Instantly share code, notes, and snippets.

View rednafi's full-sized avatar
🏠
Working from home

Redowan Delowar rednafi

🏠
Working from home
View GitHub Profile
WITH foreign_keys
     AS (SELECT conname,
                conrelid,
                confrelid,
                Unnest(conkey)  AS CONKEY,
                Unnest(confkey) AS CONFKEY
 FROM pg_constraint
@rednafi
rednafi / arch.md
Last active November 4, 2021 01:18
Django Init Model for Bro

Directory Structure

.
├── app             # I know this app name sucks.
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── __init__.py
│ ├── admin.py
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rednafi
rednafi / asyncio_limit_concurrency.py
Last active April 18, 2021 16:19
Python Asyncio MRE scripts.
import asyncio
import httpx
MAX_CONSUMERS = 50
async def make_request(url):
async with httpx.AsyncClient(http2=True) as client:
response = await client.get(url)
@rednafi
rednafi / execute_tagged.py
Created April 12, 2021 13:53
Run a tagged function in python
import argparse
import functools
import another
def tag(*name):
def outer(func):
func.tag = name
@functools.wraps(func)
@rednafi
rednafi / go.md
Last active February 28, 2021 21:03
Go

Update & Installation

#!/usr/bin/env bash

# Added bash strict mode.
set -euo pipefail

# Remove old golang versions.
whereis go | xargs -n1 sudo rm -rf
@rednafi
rednafi / update.py
Last active February 14, 2021 16:22
Update python poetry dependencies
#!/bin/python3
import toml
import subprocess
import sys
class UpdateDeps:
@rednafi
rednafi / add_slot.py
Last active January 6, 2021 18:10
add_slot.py
""" Classes and metaclasses for easier ``__slots__`` handling. """
from itertools import tee
import dis
__version__ = "2021.1.6"
__all__ = ("Slots",)
def self_assignemts(method) -> set:
@rednafi
rednafi / redis_queue.py
Last active June 27, 2022 11:40
Simple FIFO queue with Redis to run tasks asynchronously in Python.
"""Simple FIFO queue with Redis to run tasks asynchronously.
===========
Description
===========
This script implements a rudimentary FIFO task queue using Redis's list data
structure. I took a peek under Celery and RQ's source code to understand how
they've implemented the async task queue — harnessing the features of Redis and
Python's multiprocessing paradigm.
@rednafi
rednafi / logger.py
Last active December 15, 2020 19:21
Colorful logging in Python
"""Custom logger with colorized output.
MODULE_NAME: LINE_NUMBER: LOG_LEVEL: LOG_MESSAGE
Usage
======
from common.logger import logger
logger.debug(f"{__name__}: This is a debug message.")
logger.info(f"{__name__}: This is an info message.")