This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
from django.db.backends.mysql.base import DatabaseOperations | |
def py_datetime_to_mysql(d): | |
db_ops = DatabaseOperations(connection) | |
return db_ops.value_to_db_datetime(d) | |
#eg: | |
from django.db import connection | |
py_datetime_to_mysql(datetime.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#modified version off http://code.activestate.com/recipes/576602-safe-print/ | |
def sprint(*args, **kwargs): | |
"""Safely print the given string. | |
If you want to see the code points for unprintable characters then you | |
can use `errors="xmlcharrefreplace"`. | |
""" | |
errors = kwargs.get('errors', 'replace') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
manage.py runserver --insecure | |
#http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git for-each-ref --sort=-committerdate refs/heads/ | |
#http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Template("The first stooge in the list is {{ stooges.0 }}.") | |
c = Context({"stooges": ["Larry", "Curly", "Moe"]}) | |
t.render(c) | |
#or if you want to render from an existing html template | |
from django.template.loader import render_to_string | |
rendered = render_to_string('my_template.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.renderers import JSONRenderer | |
from rest_framework.response import Response | |
from rest_framework.views import APIView | |
class SimpleView(APIView): | |
renderer_classes = (JSONRenderer,) | |
permission_classes = (IsAuthenticated,) | |
def get(self, request): | |
content = {'testing': 123} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import django | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") | |
django.setup() | |
################################################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\pset pager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env TZ=Australia/Melbourne ls -al |