Skip to content

Instantly share code, notes, and snippets.

View antonioj-mattos's full-sized avatar

Antonio Jr. Mattos antonioj-mattos

View GitHub Profile
@antonioj-mattos
antonioj-mattos / .gitignore
Created August 6, 2019 21:22 — forked from smoser/.gitignore
cloud-init ubuntu nocloud example with network config
*.img
*.raw
@antonioj-mattos
antonioj-mattos / protected_media.md
Created November 18, 2019 21:07 — forked from cobusc/protected_media.md
Protected Media in Django

Protected Media in Django

Introduction

Django manages media based on the following definitions:

BASE_DIR = /var/praekelt/telkom-spliceworks/
MEDIA_ROOT = "%s/media/" % BASE_DIR
@antonioj-mattos
antonioj-mattos / django_jwt_cookie.py
Created December 3, 2019 18:14 — forked from elnygren/django_jwt_cookie.py
Teach Django to use JWT tokens inside the session cookie - plays well with django-rest-framework-jwt.
@antonioj-mattos
antonioj-mattos / celery_tasks_error_handling.py
Created February 5, 2020 21:23 — forked from darklow/celery_tasks_error_handling.py
Celery tasks error handling example
from celery import Task
from celery.task import task
from my_app.models import FailedTask
from django.db import models
@task(base=LogErrorsTask)
def some task():
return result
class LogErrorsTask(Task):
@antonioj-mattos
antonioj-mattos / celery.py
Created February 7, 2020 03:06 — forked from tapanpandita/celery.py
Transaction aware celery abstract task
class TransactionAwareTask(Task):
'''
Task class which is aware of django db transactions and only executes tasks
after transaction has been committed
'''
abstract = True
def apply_async(self, *args, **kwargs):
'''
Unlike the default task in celery, this task does not return an async
from django.contrib.admin import ModelAdmin
class MyTableAdmin(ModelAdmin):
...
paginator = LargeTablePaginator
...
@antonioj-mattos
antonioj-mattos / secure_link.php
Created October 24, 2020 01:12 — forked from bftanase/secure_link.php
generate URL for nginx secure_link
@antonioj-mattos
antonioj-mattos / pre-commit
Created December 17, 2020 23:39 — forked from mcls/pre-commit
Regex blacklist for git diff in git pre-commit hook
#!/usr/bin/env python
from subprocess import *
import sys
import re
# Add Regex to blacklist here
blacklist = [
"\+[ ]+NSLog.+" # Prevent NSLog's from being added
]
@antonioj-mattos
antonioj-mattos / bulk_upsert.py
Created May 8, 2022 23:53 — forked from aisayko/bulk_upsert.py
Postgresql bulk upsert in Python (Django)
def bulk_upsert(model, fields, values, by):
"""
Return the tuple of (inserted, updated) ids
"""
result = (None, None)
if values:
stmt = """
WITH data_set AS (
INSERT INTO %s (%s)
@antonioj-mattos
antonioj-mattos / layered.cs
Last active June 19, 2022 19:47 — forked from ralfw/layered.cs
Layered design vs stratified design
using System;
using System.Linq;
namespace layered
{
class MainClass
{
public static void Main(string[] args) {
var data = new DataLayer();
var business = new BusinessLayer(data);