Skip to content

Instantly share code, notes, and snippets.

@bakatrouble
bakatrouble / snippet.py
Last active July 16, 2017 11:55
Runtime generation of uploaded file name (Django)
@deconstructible
class RandomFileName(object):
def __init__(self, path):
self.path = os.path.join(path, "%s%s")
def __call__(self, _, filename):
extension = os.path.splitext(filename)[1]
return self.path % (uuid.uuid4(), extension)
image = models.ImageField(verbose_name=_('Image'), upload_to=RandomFileName('backgrounds'),
@bakatrouble
bakatrouble / run.py
Last active January 24, 2016 19:52
Vanilla Minecraft runner
#!/usr/bin/python3
from subprocess import Popen
from os import path
from platform import system
from uuid import uuid4
def run_game(game_path, game_data, main_class, version, uuid=str(uuid4()), xmx=1024, max_perm_size=128, more=list()):
"""