Skip to content

Instantly share code, notes, and snippets.

@gonzaloamadio
gonzaloamadio / gist:d42acb8cce05061e674a7f698f03972c
Created October 25, 2021 20:49
OtherFieldValidator Django
class OtherFieldValidatorInSerializer:
"""
A validator to be inherited from, that will give use the
possibility of validate two fields.
More exaplanation on comments along the code.
TODO: Easily extensible to a list of fields
USAGE EXAMPLE:
(For a model that has to fields, date_start and date_end)
@gonzaloamadio
gonzaloamadio / test_unmanaged_models.md
Created May 27, 2021 18:40 — forked from raprasad/test_unmanaged_models.md
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)

Scenario

  • Django 1.9 application with two databases:
    • Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to False
      • 'managed': False
    • Default database holding django specific tables (e.g. auth_user, django_content_type, etc)

Testing Woes

import uuid
from django.db import models
class UUIDField(
models.UUIDField
):
def __init__(self, *args, **kwargs):
self.version = kwargs.pop('version', 1)
#!/usr/bin/env bash
log() { echo -e "\e[0;33m${1}\e[0m"; }
# Ask for the administrator password upfront.
sudo -v
log 'Empty the Trash on all mounted volumes and the main HDD...'
sudo rm -rfv /Volumes/*/.Trashes
sudo rm -rfv ~/.Trash
@gonzaloamadio
gonzaloamadio / debugging_decorators.py
Last active November 5, 2019 21:45 — forked from chadgh/debugging_decorators.py
python decorators for; debugging, threading
def timeit(function):
'''Decorator used for debugging. Prints the call and how long it took.'''
def timed(*args, **kwargs):
ts = time.time()
result = function(*args, **kwargs)
te = time.time()
print("{0} ({1}, {2}) {3:.2} sec"
.format(function.__name__, args, kwargs, te - ts))
class CreateJob(UseCaseInterface):
def __init__(
self,
repository: JobRepositoryInterface,
title,
date_start,
date_end,
slug=None
):
self._title = title
@gonzaloamadio
gonzaloamadio / linux admin basic commands
Last active July 18, 2018 09:39
Various linux commands for administrators, and for everyone
--- Connect to windows via rdesktop ---
> rdesktop -u administrador -g1500x800 10.11.11.97
--- Connect to linux via ssh ---
> ssh {user}@{ip or dns-name}
Example
> ssh [email protected]
@gonzaloamadio
gonzaloamadio / .vimrc
Last active July 6, 2020 14:50
My ~/.vimrc configuration. Mostly oriented for python
" # Fisa-vim-config
" # http://fisadev.github.io/fisa-vim-config/
" # version: 8.2
" https://realpython.com/vim-and-python-a-match-made-in-heaven/#vim-extensions
" # Other ref: https://nvie.com/posts/how-i-boosted-my-vim/
set encoding=utf-8
let using_neovim = has('nvim')
let using_vim = !using_neovim
########## LOGGIN
# Put this inside settings.py (if you have separated settings, put it on base setting)
# If DEBUG=True, all logs (including django logs) will be
# written to console and to debug_file.
# If DEBUG=False, logs with level INFO or higher will be
# saved to production_file.