Skip to content

Instantly share code, notes, and snippets.

View rafaelhenrique's full-sized avatar

Rafael Henrique da Silva Correia rafaelhenrique

View GitHub Profile
>>> from datetime import date
>>> with patch('mymodule.date') as mock_date:
... mock_date.today.return_value = date(2010, 10, 8)
... mock_date.side_effect = lambda *args, **kw: date(*args, **kw)
...
... assert mymodule.date.today() == date(2010, 10, 8)
... assert mymodule.date(2009, 6, 8) == date(2009, 6, 8)
...
@rafaelhenrique
rafaelhenrique / localized.py
Created December 15, 2016 13:33
Django localized date and time
import pytz
from django.utils import timezone
local_tz = pytz.timezone('America/Sao_Paulo')
datetime_now = timezone.now()
localized_date = datetime_now.astimezone(local_tz)
date_now = localized_date.strftime('%d%m%Y') # DDMMAAAA
time_now = localized_date.strftime('%H%M%S') # HHMMSS
- Nginx -> Camada em cima da aplicação
para que nem todas as requisições sejam
servidas pela aplicação
APLICAÇÃO <----> NGINX <----> INTERNET
<----- USUÁRIO XPTO
-----> USUÁRIO XPTO
APLICAÇÃO <---- NGINX
-----> USUÁRIO XPTO
@rafaelhenrique
rafaelhenrique / resumo_deploy_grupo_de_estudo
Created October 11, 2016 02:46
Resumo das aulas de Deploy do Grupo de Estudos Python Sorocaba
- Nginx -> Camada em cima da aplicação
para que nem todas as requisições sejam
servidas pela aplicação
APLICAÇÃO <----> NGINX <----> INTERNET
<----- USUÁRIO XPTO
-----> USUÁRIO XPTO
APLICAÇÃO <---- NGINX
-----> USUÁRIO XPTO
@rafaelhenrique
rafaelhenrique / example_django_settings.py
Last active September 23, 2016 12:40
Implement log filter to use on Django to "by-pass" log when run tests
# ..... ommited lines
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
'disable_on_test': {
@rafaelhenrique
rafaelhenrique / create_postgresql_container.sh
Last active October 8, 2018 17:39
Create postgresql docker container
#!/bin/bash
VOLUME=$(echo $VOLUME)
PORT=$(echo $PORT)
NAME=$(echo $NAME)
POSTGRES_PASSWORD=$(echo $POSTGRES_PASSWORD)
VERSION="latest"
DATE=$(date +"%d%m%Y-%H%M%S")
PARAM="$1"
if [ "$PARAM" == '-h' ]; then
@rafaelhenrique
rafaelhenrique / utils.py
Last active September 3, 2016 17:04
Utils
import string
import random
def id_generator(size=10, chars=None):
"""
Generate a random string with 10 characters.
This function have more explain here:
http://stackoverflow.com/questions/2257441/
@rafaelhenrique
rafaelhenrique / test_utils.py
Created September 3, 2016 16:52
Functions to help test
import re
def count_words(word, sentence):
"""Count the number of occurrences of a word in the sentence"""
match = re.compile(word)
return len(match.findall(sentence))
@rafaelhenrique
rafaelhenrique / generate_secret_key.py
Created September 3, 2016 16:44
Generate a randon SECRET_KEY for Flask/Django... whatever
import random
"""
Some parts of this code were extracted from Django framework
https://github.com/django/django/blob/master/django/utils/crypto.py
"""
random = random.SystemRandom()
# -*- coding: utf-8 -*-
import json
from urllib import urlopen
import time
DEBUG = True
TEMPO = 5