Skip to content

Instantly share code, notes, and snippets.

@develmaycare
develmaycare / duration_display.py
Created September 30, 2017 19:47
Human Friendly Duration Display
# Avoid magic numbers.
seconds_per_hour = 3600
minutes_per_hour = 60
# Duration is a total number of seconds, but get be derived from timedelta.total_seconds().
t = timedelta(hours=2, minutes=15)
total_seconds = t.total_seconds()
# Store output in a list.
a = list()
@develmaycare
develmaycare / django.html
Last active March 18, 2018 18:42
Twitter Bootstrap Row Cycles in Django and Jinja
{# Assuming a page object with one or more instances of a content block: #}
{% for block in page.blocks %}
{# Start a new row every third block. #}
{% cycle '<div class="row">' "" "" %}
<div class="col-md-4">
{{ block }}
</div>
{# End every third row. #}
{% cycle "" "" '</div>' %}
{% endfor %}
@develmaycare
develmaycare / django-script.py
Created May 7, 2018 13:40
Standalone Django scripting.
#! /usr/bin/env python
import os
import sys
# Define the path to the project.
PROJECT_PATH = os.path.abspath(os.path.join("example", "source"))
# Let Django know where things are.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")