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
""" | |
Dump out objects and all nested associations. | |
""" | |
import sys | |
from django.apps import apps | |
from django.contrib.admin.utils import NestedObjects | |
from django.core import serializers | |
from django.core.management import BaseCommand | |
from django.db import router |
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 logging | |
from os.path import exists | |
from os import remove, getpid | |
from django.core.management.base import BaseCommand | |
logger = logging.getLogger(__name__) | |
class LockedCommand(BaseCommand): | |
""" |
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 | |
from __future__ import unicode_literals | |
import logging | |
from django.core.management.base import BaseCommand, CommandError | |
from django.apps import apps | |
from xlsxwriter.workbook import Workbook | |
logger = logging.getLogger(__name__) |
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 smtpd | |
import asyncore | |
import logging | |
import email | |
from email.header import decode_header | |
import requests | |
logger = logging.getLogger(__name__) | |
class CustomSMTPServer(smtpd.SMTPServer): |
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.http import HttpResponse | |
class AllowCORSMixin(object): | |
def add_access_control_headers(self, response): | |
response["Access-Control-Allow-Origin"] = "*" | |
response["Access-Control-Allow-Methods"] = "GET, OPTIONS" | |
response["Access-Control-Max-Age"] = "1000" | |
response["Access-Control-Allow-Headers"] = "X-Requested-With, Content-Type" |
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 gc | |
def queryset_iterator(qs, batchsize = 500, gc_collect = True): | |
iterator = qs.values_list('pk', flat=True).order_by('pk').distinct().iterator() | |
eof = False | |
while not eof: | |
primary_key_buffer = [] | |
try: | |
while len(primary_key_buffer) < batchsize: | |
primary_key_buffer.append(iterator.next()) |
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 [ -z $1 ]; then | |
echo "Usage: $0 app_label" | |
exit 1 | |
fi | |
app=$1 # this is the name of the app where we want to update the last migration | |
# get the list of known migrations for the app |
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
angular.module('canvas_share', ['ionic', 'ngCordova']) | |
.controller('CanvasShareCtrl', function($scope, $cordovaSocialSharing, $q) { | |
var buildImage = function() { | |
var deferred = $q.defer(); | |
// create the canvas | |
var canvas = document.createElement('canvas'); | |
canvas.width = 400; | |
canvas.height = 120; | |
var context = canvas.getContext('2d'); | |
// draw a rectangular white frame for our content |
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
function myFunction() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var range = sheet.getDataRange(); | |
var cells = range.getValues(); | |
var latitudes = []; | |
var longitudes = []; | |
for (var i = 0; i < cells.length; i++) { |
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.http import HttpResponse | |
from .models import FirstModel | |
def my_view(request): | |
# this queryset contains about 100k records | |
# each of them has many ForeignKeys to other models | |
huge_queryset = FirstModel.objects.all().iterator() | |
f = open('dumb.dump', 'w') |
NewerOlder