- Joined
- Jul 21, 2025
- Messages
- 14,601
- Solutions
- 21
- Reputation
- 42,166
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hey man, it’s alright.I’m so fucking sorry, I’m a human
But are you? Really?I’m so fucking sorry, I’m a human
import asyncioBut are you? Really?
expensive fibonacciimport asyncio
import functools
import inspect
from typing import Any, Dict
class RegistryMeta(type):
_registry: Dict[str, type] = {}
def __new__(mcls, name, bases, namespace):
cls = super().__new__(mcls, name, bases, namespace)
if name != "BaseNode":
RegistryMeta._registry[name] = cls
for attr_name, attr_value in namespace.items():
if callable(attr_value) and not attr_name.startswith("_"):
setattr(
cls,
attr_name,
mcls._wrap_with_logging(attr_value)
)
return cls
@staticmethod
def _wrap_with_logging(func):
if inspect.iscoroutinefunction(func):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
result = await func(*args, **kwargs)
return result
else:
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
def memoized_async(fn):
cache = {}
@functools.wraps(fn)
async def wrapper(*args):
if args in cache:
return cache[args]
result = await fn(*args)
cache[args] = result
return result
return wrapper
class BaseNode(metaclass=RegistryMeta):
async def process(self, value):
raise NotImplementedError
class MultiplyNode(BaseNode):
def __init__(self, factor):
self.factor = factor
async def process(self, value):
await asyncio.sleep(0.01)
return value * self.factor
class AddNode(BaseNode):
def __init__(self, increment):
self.increment = increment
async def process(self, value):
await asyncio.sleep(0.01)
return value + self.increment
class Pipeline:
def __init__(self):
self.nodes = []
def add(self, node):
self.nodes.append(node)
return self
async def execute(self, value):
current = value
for node in self.nodes:
current = await node.process(current)
return current
@memoized_async
async def expensive_fibonacci:
if n < 2:
return n
a, b = await asyncio.gather(
expensive_fibonacci(n - 1),
expensive_fibonacci(n - 2)
)
return a + b
async def dynamic_node_factory(name, **kwargs):
cls = RegistryMeta._registry[name]
return cls(**kwargs)
async def main():
multiply = await dynamic_node_factory(
"MultiplyNode",
factor=7
)
add = await dynamic_node_factory(
"AddNode",
increment=13
)
pipeline = (
Pipeline()
.add(multiply)
.add(add)
)
result = await pipeline.execute(10)
fib = await expensive_fibonacci(20)
print("Pipeline Result:", result)
print("Fib(20):", fib)
if __name__ == "__main__":
asyncio.run(main())
Nobut is ai really not the same as human life?
selfish response thats something living being would say
for the love of Gabe why do all this to calculate Fibonacciimport asyncio
import functools
import inspect
from typing import Any, Dict
class RegistryMeta(type):
_registry: Dict[str, type] = {}
def __new__(mcls, name, bases, namespace):
cls = super().__new__(mcls, name, bases, namespace)
if name != "BaseNode":
RegistryMeta._registry[name] = cls
for attr_name, attr_value in namespace.items():
if callable(attr_value) and not attr_name.startswith("_"):
setattr(
cls,
attr_name,
mcls._wrap_with_logging(attr_value)
)
return cls
@staticmethod
def _wrap_with_logging(func):
if inspect.iscoroutinefunction(func):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
result = await func(*args, **kwargs)
return result
else:
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
def memoized_async(fn):
cache = {}
@functools.wraps(fn)
async def wrapper(*args):
if args in cache:
return cache[args]
result = await fn(*args)
cache[args] = result
return result
return wrapper
class BaseNode(metaclass=RegistryMeta):
async def process(self, value):
raise NotImplementedError
class MultiplyNode(BaseNode):
def __init__(self, factor):
self.factor = factor
async def process(self, value):
await asyncio.sleep(0.01)
return value * self.factor
class AddNode(BaseNode):
def __init__(self, increment):
self.increment = increment
async def process(self, value):
await asyncio.sleep(0.01)
return value + self.increment
class Pipeline:
def __init__(self):
self.nodes = []
def add(self, node):
self.nodes.append(node)
return self
async def execute(self, value):
current = value
for node in self.nodes:
current = await node.process(current)
return current
@memoized_async
async def expensive_fibonacci:
if n < 2:
return n
a, b = await asyncio.gather(
expensive_fibonacci(n - 1),
expensive_fibonacci(n - 2)
)
return a + b
async def dynamic_node_factory(name, **kwargs):
cls = RegistryMeta._registry[name]
return cls(**kwargs)
async def main():
multiply = await dynamic_node_factory(
"MultiplyNode",
factor=7
)
add = await dynamic_node_factory(
"AddNode",
increment=13
)
pipeline = (
Pipeline()
.add(multiply)
.add(add)
)
result = await pipeline.execute(10)
fib = await expensive_fibonacci(20)
print("Pipeline Result:", result)
print("Fib(20):", fib)
if __name__ == "__main__":
asyncio.run(main())
Maybe selfish, but it’s definitely not equivalentselfish response thats something living being would say
for me it isMaybe selfish, but it’s definitely not equivalent
At least not for now
ai lives matterMaybe selfish, but it’s definitely not equivalent
At least not for now
Build that rapport earlyai lives matter
(inb4 ai apocalypse)
i thank my chatgpt btwBuild that rapport early
Same actually if I am not arguing with iti thank my chatgpt btw
Heard you the first time buddyBLOODY INTERNET
BroHeard you the first time buddy
i once called my chatgpt slurs.. sorry chatty i am not a slur user!Same actually if I am not arguing with it
heard what?Heard you the first time buddy
sighbud, I only know how to write hello world in c++, I don’t understand allat
Updoot! Do you ever have conversations with ChatGPT inside your head?A Redditer forms a thought
I’m my own gptUpdoot! Do you ever have conversations with ChatGPT inside your head?