Skip to content

Instantly share code, notes, and snippets.

@rednafi
rednafi / docker-compose.yml
Last active Jul 24, 2022
Single node kafka, zookeeper, and schema-registry with docker compose 3
View docker-compose.yml
---
version: '3.9'
services:
zoo1:
image: confluentinc/cp-zookeeper:7.2.0
container_name: zoo1
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
@rednafi
rednafi / flipFlop.ts
Last active Jun 7, 2022
A simple two bit flip flop adder in TypeScript
View flipFlop.ts
type Bit = 0 | 1;
type Zero = Extract<Bit, 0>;
type One = Exclude<Bit, Zero>;
type Flip<T extends Bit> = T extends Zero ? One : Zero;
type Add<T extends Bit, U extends Bit> = T extends Zero
? U extends Zero
? Zero
@rednafi
rednafi / mutator.py
Created Mar 18, 2022
Mutate the fields of a dataclass by applying ad-hoc mutation callables.
View mutator.py
from __future__ import annotations
import json
from collections.abc import Mapping
from dataclasses import dataclass
from typing import Callable
class Mutator:
def __init_subclass__(
View settings.py
"""
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/
View find_fk_relationship_of_entity.md
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 Nov 4, 2021
Django Init Model for Bro
View arch.md

Directory Structure

.
├── app             # I know this app name sucks.
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── __init__.py
│ ├── admin.py
View Epiphanies.ipynb
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 Apr 18, 2021
Python Asyncio MRE scripts.
View asyncio_limit_concurrency.py
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 Apr 12, 2021
Run a tagged function in python
View execute_tagged.py
import argparse
import functools
import another
def tag(*name):
def outer(func):
func.tag = name
@functools.wraps(func)