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
class YourResource(ModelResource): | |
def wrap_view(self, view): | |
""" | |
Wraps views to return custom error codes instead of generic 500's | |
""" | |
@csrf_exempt | |
def wrapper(request, *args, **kwargs): | |
try: |
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
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'class': 'django.utils.log.AdminEmailHandler' | |
}, | |
'null': { | |
'level':'DEBUG', |
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
#!/bin/bash | |
if [[ $1 == "" && $2 == "" ]] | |
then | |
echo "USAGE: $0 SINCE_DATE [AUTHOR_PATTERN]" | |
exit | |
fi | |
DATE=$1 # 10-1-2011, 2012-04-22, etc | |
AUTHOR=$2 # author pattern (regexp) |
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
armv5te-android-gcc armv5te-linux-rvct armv5te-linux-gcc | |
armv5te-none-rvct | |
armv6-darwin-gcc armv6-linux-rvct armv6-linux-gcc | |
armv6-none-rvct | |
armv7-android-gcc armv7-darwin-gcc armv7-linux-rvct | |
armv7-linux-gcc armv7-none-rvct | |
mips32-linux-gcc | |
ppc32-darwin8-gcc ppc32-darwin9-gcc ppc32-linux-gcc | |
ppc64-darwin8-gcc ppc64-darwin9-gcc ppc64-linux-gcc | |
sparc-solaris-gcc |
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
// Just before switching jobs: | |
// Add one of these. | |
// Preferably into the same commit where you do a large merge. | |
// | |
// This started as a tweet with a joke of "C++ pro-tip: #define private public", | |
// and then it quickly escalated into more and more evil suggestions. | |
// I've tried to capture interesting suggestions here. | |
// | |
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_, | |
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant, |
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
""" This is a quick fix to provide full dehydration by demand | |
on Django Tastypie. | |
In order to use it you can query for: | |
/api/v1/user/1/related_full=True | |
""" | |
class RelatedResource(ModelResource): |
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
""" | |
Test (data) migrations in Django. | |
This uses py.test/pytest-django (the `transactional_db` fixture comes from there), | |
but could be easily adopted for Django's testrunner: | |
from django.test.testcases import TransactionTestCase | |
class FooTestcase(TransactionTestCase): | |
def test_with_django(self): |
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
#!/usr/bin/env python | |
''' | |
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library. | |
Features: | |
* Map URI patterns using regular expressions | |
* Map any/all the HTTP VERBS (GET, PUT, DELETE, POST) | |
* All responses and payloads are converted to/from JSON for you |
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
# based on https://gist.github.com/blueyed/4fb0a807104551f103e6 | |
# and on https://gist.github.com/TauPan/aec52e398d7288cb5a62895916182a9f (gistspection!) | |
from django.core.management import call_command | |
from django.db import connection | |
from django.db.migrations.executor import MigrationExecutor | |
import pytest | |
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 functools | |
def force_async(fn): | |
''' | |
turns a sync function to async function using threads | |
''' | |
from concurrent.futures import ThreadPoolExecutor | |
import asyncio | |
pool = ThreadPoolExecutor() |
OlderNewer