Skip to content

Instantly share code, notes, and snippets.

@avoiney
avoiney / .env
Created July 28, 2021 06:47
Directus under non root path with nginx
DIRECTUS_KEY=<...>
DIRECTUS_SECRET=<...>
DIRECTUS_DB_DATABASE=<...>
DIRECTUS_DB_USER=<...>
DIRECTUS_DB_PASSWORD=<...>
DIRECTUS_CACHE_ENABLED=true
DIRECTUS_CACHE_STORE=redis
DIRECTUS_ADMIN_EMAIL=<...>
DIRECTUS_ADMIN_PASSWORD=<...>
DIRECTUS_PUBLIC_URL=https://<server_name>/directus/ # server_name is the one used in nginx. Note the slash at the end.
""" A decorator to easily use cProfile on function """
import cProfile
def profiler(sort=-1, use_globals=False, use_locals=True):
def decr(func):
def wrp(*args, **kwargs):
g = globals() if use_globals else None
l = locals() if use_locals else None
cProfile.runctx("func(*args, **kwargs)", g, l, sort=sort)
return func(*args, **kwargs)
""" Tool function to convert Generalized Time string
to Python datetime object
"""
import datetime
import pytz
def gt_to_dt(gt):
""" Convert GeneralizedTime string to python datetime object
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
@avoiney
avoiney / FileField_manual_initialisation.py
Last active June 12, 2021 12:46
Manually associate an existing file to a model FileField
# Assuming you have a Article Model like this
# class Article(models.Model):
# ... Some field
# media = models.FileField(upload_to="path_to_inner_media_folder", blank=True)
from django.core.files.base import ContentFile
import os
# Create an article with the associated model
new_article = Article()