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
@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 / 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 / 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 / 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 / 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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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
WITH foreign_keys
     AS (SELECT conname,
                conrelid,
                confrelid,
                Unnest(conkey)  AS CONKEY,
                Unnest(confkey) AS CONFKEY
 FROM pg_constraint
"""
Django settings for main project.
Generated by 'django-admin startproject' using Django 4.0.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
@rednafi
rednafi / mutator.py
Created March 18, 2022 20:32
Mutate the fields of a dataclass by applying ad-hoc mutation callables.
from __future__ import annotations
import json
from collections.abc import Mapping
from dataclasses import dataclass
from typing import Callable
class Mutator:
def __init_subclass__(