Skip to content

Instantly share code, notes, and snippets.

@jayhale
jayhale / quantize_time.py
Last active September 7, 2018 14:35
Python time quantizer
"""
A simple time quantizer for python. Takes in a time and gives back the
quantized time given resolution in seconds. Always rounds down.
"""
from datetime import datetime
def quantize_time(time, resolution):
"""Round a time object to the previous time appropriate for resolution"""
@jayhale
jayhale / settings.py
Last active March 3, 2019 16:52
Django on Zeit Now: now-django-example/now_app/settings.py
# now-django-example/now_app/settings.py
INSTALLED_APPS = [
# ...
'example_app',
]
@jayhale
jayhale / urls.py
Created March 3, 2019 16:54
Django on Zeit Now: now-django-example/now_app/urls.py
# now-django-example/now_app/urls.py
from django.urls import path, include
urlpatterns = [
# ...
path('', include('example_app.urls')),
]
@jayhale
jayhale / views.py
Last active March 12, 2019 21:28
Django on Zeit Now: now-django-example/example_app/views.py
# now-django-example/example_app/views.py
from datetime import datetime
from django.http import HttpResponse
def index(request):
now = datetime.now()
html = f'''
<html>
<body>
<h1>Hello from Zeit Now!</h1>
@jayhale
jayhale / urls.py
Last active March 12, 2019 21:28
Django on Zeit Now: now-django-example/example_app/urls.py
# now-django-example/example_app/urls.py
from django.urls import path
from example.views import index
urlpatterns = [
path('', index),
]
@jayhale
jayhale / now.json
Last active May 3, 2019 12:07
Django on Zeit Now: now-django-example/now.json
{
"version": 2,
"name": "now-django-example",
"builds": [{
"src": "now_app/wsgi.py",
"use": "@ardnt/now-python-wsgi",
"config": { "maxLambdaSize": "15mb" }
}],
"routes": [{
"src": "/(.*)",
@jayhale
jayhale / index.py
Last active March 12, 2019 21:41
Django on Zeit Now: now-django-example/index.py
# now-django-example/index.py
from now_app.wsgi import application
@jayhale
jayhale / settings.py
Created March 12, 2019 21:50
Django on Zeit Now: now-django-example/now_app/settings.py
# now-django-example/now_app/settings.py
# ...
ALLOWED_HOSTS = ['.now.sh'] # Allow *.now.sh
# ...
DATABASES = {} # Prevent Django from loading an adapter
# ...
@jayhale
jayhale / requirements.txt
Last active May 3, 2019 12:04
Django on Zeit Now: now-django-example/requirements.txt
Django >=2.1,<2.2
@jayhale
jayhale / settings.py
Created May 7, 2019 11:51
Django staticfiles on Zeit Now: settings.py
# now_app/settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.abspath(__file__)))
# ...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static')