This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enter python manage.py shell | |
from django.core.mail import EmailMessage | |
email = EmailMessage('Subject', 'Message', to=['example@example.com']) | |
email.send() | |
# It should return 1 if everything is ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelA(models.Model): | |
attr1 = models.Charfield() | |
attr2 = models.Charfield(unique=True) | |
class ModelB(models.Model): | |
foreign = models.ForeignKey(ModelA) | |
class OtherFieldUniqueSerializer(serializers.PrimaryKeyRelatedField): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.permissions import BasePermission | |
class IsAjaxPermission(BasePermission): | |
""" | |
Check is request is ajax. | |
""" | |
def has_object_permission(self, request, view, obj): | |
return request.is_ajax() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ps aux | grep "scrapy crawl" | grep -v grep | awk "{ print \$2 }" | xargs kill -9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pdb_check=$(git grep pdb -- '*.py') | |
if [ ${#pdb_check} -gt 0 ] | |
then | |
echo "COMMIT REJECTED: commit contains code with break points. Please remove before commiting." | |
echo $pdb_check | |
exit 1 | |
else | |
echo "Code contains no break points" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from Crypto.Cipher import XOR | |
import base64 | |
import functools | |
import hashlib | |
def func_encrypt(key, plaintext): | |
cipher = XOR.new(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import psycopg2 | |
import sys | |
host = '' | |
dbname = '' | |
user = '' | |
password = '' | |
port = 5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Installation | |
wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add - | |
sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list | |
sudo apt-get update && sudo apt-get install s3cmd | |
# Configuration | |
s3cmd --configure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from itertools import tee | |
class ListaTelefones(object): | |
def __init__(self, lista_de_telefones): | |
self.telefones = lista_de_telefones.split() | |
self.telefones_validos = [] |