Daniel Roy Greenfeld Blog
The “Daniel Roy Greenfeld Blog” delves into various aspects of Python programming, machine learning, and AI applications. It explores topics such as data augmentation for machine learning, Python scripts for everyday use, and the speed considerations in Python programming. Additionally, it discusses the importance of maintaining conversation history in AI applications using short-term memory in databases. The blog provides insights into practical Python applications, best practices, and innovative solutions for developers and data scientists. Through a blend of tutorials, guides, and real-world examples, the blog offers valuable information for individuals interested in enhancing their Python skills and exploring cutting-edge technologies.
Exploring flexicache
```python Import necessary libraries from fastcore.xtras import flexicache, time_policy, mtime_policy Libraries used in testing cache validity and cache invalidation from random import randint from p...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: ^ bitwise XOR
```python False ^ False ^ False ``` False ```python print(True ^ False ^ False) print(False ^ True ^ False) print(False ^ False ^ True) ``` True True True ```python print(True ^ True ^ False) print(T...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: Pipe operator for merging dictionaries
```python a = {'a': 1, 'b': 2} b = {'c': 3, 'd': 4} Similar to a.update(b), but returns a new dictionary instead of making a change in-place merged = a | b print(a) ``` ```python left = {'a': 1, 'b':...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
Pi Day
```python from math import pi ``` ```python print(pi) ``` 3.141592653589793 ```python print(pi**pi) ``` 36.4621596072079
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: Undecorating a functools.wraps decorated function
```python from functools import wraps def kerpow(f): """Prints the string KERPOW!""" @wraps(f) def wrapper(*args, **kwds): print(f'KERPOW {f.__name__}!') return f(*args, **kwds) return wrapper ``` ``...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
Building a playing card deck
```python import pathlib from fastcore.basics import AttrDict, store_attr from fastcore.utils import L, patch from fasthtml.common import show, NotStr from rich import print ``` ```python class Card:...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
Fastcore L
```python from fastcore.foundation import L ``` ```python lst1 = L(range(100)) lst1 ``` ```python lst2 = L(list(range(5))+list(range(5))) lst2 ``` ```python lst2.unique().filter(lambda x: not x % 2 a...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: Using inspect and timeit together
```python def get_random_string(length=10): from random import choice from string import ascii_letters return ''.join(choice(ascii_letters) for _ in range(length)) get_random_string() ``` ```python f...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
Exploring fastcore bunch classes
```python from fastcore.basics import AttrDict ``` ```python daughter = AttrDict(name='Uma', age=6) daughter ``` ```python daughter == {'age': 6, 'name': 'Uma'} ``` ```python daughter['name'] ``` ```...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: yield from
```python def row_fetcher(rows=5): for x in range(rows): yield x row_fetcher() ``` ```python cursor = row_fetcher() print(next(cursor)) for x in cursor: print(x) ``` ```python def row_fetcher2(rows=5...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
TIL: types.SimpleNamespace is a Bunch class
```python from types import SimpleNamespace as ns ``` ```python daughter = ns(age=6, name='Uma') daughter ``` ```python daughter.name ``` ```python daughter.__dict__ ``` ```python ages = [ns(age=i, n...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents
File Location Fixup
```python from pathlib import Path from yaml import safe_load ```python for path in Path('posts').glob('*.md'): Get the year from the frontmatter raw = path.read_text() metadata = safe_load(raw.split...
📚 Read more at Daniel Roy Greenfeld Blog🔎 Find similar documents