Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile
import pydantic
def to_json(cls):
cls.to_json = lambda self: pydantic.RootModel[cls](self).model_dump_json()
return cls
@to_json
@pydantic.dataclasses.dataclass
class A:
@pydanny
pydanny / rebase.sh
Created December 18, 2023 09:56
Modifying a specific commit
git rebase -i HASH
# Change code here
git commit --all --amend --no-edit -n
git rebase --continue
@app.command()
def serve(site: Path = Path("site")):
    """Serve the site"""
    check_call(["python", "-m", "http.server", "8000", "-d", site])
@app.command()
def serve2(site: Path = Path("site"), port: int = 8000):
import os
import glob
from dj_notebook import activate
def test_thing():
print(os.getcwd())
os.chdir("tests/django_test_project")
print(glob.glob("*"))
# pip install -e '.[test]'
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "simplicity"
version = "0.7.0"
description = "A straightforward and opinionated cookiecutter template for building Python packages."
daniel --- marcia

Want to to come work with me at a $US2 billion dollar unicorn fighting climate change so our children have a greener future?

If you can you legally work right now in the USA, UK, Australia, Japan, Germany, or New Zealand, please apply by clicking the link below. We're hiring for many kinds of skills (marketing, design, customer support, etc), not just writing software.

If you can't yet legally work in one of the listed countries, don't worry. In the months and years to come we'll be opening offices in more countries around the world.

https://jobs.lever.co/octoenergy

# Python start-up file
# --------------------
# Ensure a PYTHONSTARTUP environment variable points to the location of this file.
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP
# Stolen 100% from David Winterbottom's file that I can't find right now.
# Always have pp available
from pprint import pprint as pp
# Pre-emptively import datetime as I use it a lot.
zip = 90213 # common US developer mistake
id = 46
map = Map()
object = MyObject()
obj = MyObject()
object_ = MyObject()
map_obj = Map()
@pydanny
pydanny / more_married.py
Last active December 30, 2020 01:12
More Married
"""
Audrey and I met on February 18, 2020. We were married on December 27th, 2020.
This programs calculates how much more we've been married than not married.
1. On November 4, 2017 our time married was now half the time we had been together.
2. On September 9, 2021 our time married will be twice as much as we knew each other.
3. On July 21, 2025, we
"""
from datetime import datetime