Skip to content

Instantly share code, notes, and snippets.

@gonzaloamadio
gonzaloamadio / test_unmanaged_models.md
Created May 27, 2021 — forked from raprasad/test_unmanaged_models.md
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)
View test_unmanaged_models.md

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

View model_fields.py
import uuid
from django.db import models
class UUIDField(
models.UUIDField
):
def __init__(self, *args, **kwargs):
self.version = kwargs.pop('version', 1)
View mac_clean.sh
#!/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 Nov 5, 2019 — forked from chadgh/debugging_decorators.py
python decorators for; debugging, threading
View debugging_decorators.py
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))
View use_case.py
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 Jul 18, 2018
Various linux commands for administrators, and for everyone
View linux admin basic commands
--- 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 root@linux-server.domain.com
@gonzaloamadio
gonzaloamadio / .vimrc
Last active Jul 6, 2020
My ~/.vimrc configuration. Mostly oriented for python
View .vimrc
" # 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
View gist:764bb66febcab4a2c0f48f1791a62b13
########## 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.