Skip to content

Instantly share code, notes, and snippets.

View RobertKolner's full-sized avatar

Robert Kolner RobertKolner

View GitHub Profile
RobertKolner / gist:62914524412ddf955c55
Last active August 29, 2015 14:10
Basic generic django file upload function. Compatible with Froala Editor.
from django.conf import settings
from import default_storage
from django.http import HttpResponse
import json
import os
def upload_file(request):
if request.method.lower() != 'post':
return HttpResponse('Invalid method {}. Only POST allowed.'.format(request.method.upper()), status=405)
RobertKolner /
Last active August 29, 2015 14:22
Remove duplicates from list
from types import GeneratorType
def remove_duplicates(iterable, key=None):
iterable_class = type(iterable)
if iterable_class in [dict, set]:
raise TypeError("You can't remove duplicates from a {}!".format(iterable_class))
if not key:
_key = lambda a: a
RobertKolner /
Last active August 15, 2018 10:11
[Note: for a better version, visit here:] Temporarily disable all signals in django
from collections import defaultdict
from django.db.models.signals import *
class DisableSignals(object):
def __init__(self, disabled_signals=None):
self.stashed_signals = defaultdict(list)
self.disabled_signals = disabled_signals or [
pre_init, post_init,
pre_save, post_save,
RobertKolner /
Created November 11, 2021 10:22
Use poetry to write requirements.txt. Potentially useful with pre-commit in cases when the project is deployed to a service that assumes existence of requirements.txt (for instance Google Cloud Functions).
#!/usr/bin/env bash
NEW_REQUIREMENTS=$(poetry export -f requirements.txt --without-hashes | cut -d';' -f1)
if [ ! -f requirements.txt ]; then
echo "requirements.txt does not exist!"
poetry export --without-hashes | cut -d';' -f1 > requirements.txt
exit 1
REQUIREMENTS=$(cat requirements.txt)