Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile
lst = [190,200,210,70,60,150,170,90]
previous = 0
streak_length = 0
for current in lst:
if previous < current:
streak_length += 1
else:
print(streak_length)
previous = 0
  1. Build the project locally to make sure it builds
pip install -U build
python -m build
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
@pydanny
pydanny / field.html
Created November 8, 2011 16:33
django-uni-form + Twitter Bootstrap
<!-- this usually goes in <project-root>/templates/uni_form/field.html -->
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="clearfix {% if field.errors %}error{% endif %}">
<label for="{{ field.auto_id }}" {% if field.field.required %}class="requiredField"{% endif %}>
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
<div class="input">
@pydanny
pydanny / api.group_permissions.py
Created December 31, 2011 20:30
django-rest-framework permissions by groups
""" User Django Rest Framework to check to see if an authenticated user
is in a particular group
Usage::
from api.group_permissions import GroupAPIGETPermission
class SearchProductView(View):
permissions = (IsAuthenticated, GroupAPIGETPermission,)