Skip to content

Instantly share code, notes, and snippets.

View test_s3.py
from boto.s3.connection import S3Connection
conn = S3Connection('awskey', 'awssecret')
bucket = conn.get_bucket('awsbucket')
@arthuralvim
arthuralvim / Vagrantfile
Last active Aug 29, 2015
Playing with Docker.
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$script = <<-SCRIPT
apt-get update
locale-gen en_US en_US.UTF-8 pt_BR pt_BR.utf8 pt_PT.utf8
dpkg-reconfigure locales
apt-get install -y --force-yes curl git
@arthuralvim
arthuralvim / provyfile-2.py
Last active Aug 29, 2015
Examples of Provyfile.
View provyfile-2.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import AptitudeRole
from provy.more.debian import NginxRole
from provy.more.debian import SupervisorRole
from provy.more.debian import TornadoRole
from provy.more.debian import UserRole
@arthuralvim
arthuralvim / breakpoint.less
Last active Aug 29, 2015
Bootstrap 3 Media Queries for Breakpoints.
View breakpoint.less
// Custom Iphone screen (MIN)
@screen-iphone-min: 320px !default;
// Extra small screen / phone (MIN)
@screen-xs-min: 480px !default;
// Small screen / tablet (MIN)
@screen-sm-min: 768px !default;
// Medium screen / desktop (MIN)
@screen-md-min: 992px !default;
// Large screen / wide desktop (MIN)
@screen-lg-min: 1200px !default;
@arthuralvim
arthuralvim / email_send_check.py
Created Aug 28, 2014
Fast check if your SMTP settings are ok.
View email_send_check.py
# 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.
@arthuralvim
arthuralvim / serializers.py
Created Sep 7, 2014
[Django Rest Framework] Serializer for a PrimaryKeyRelatedField where we use a unique key instead of the primary key.
View serializers.py
class ModelA(models.Model):
attr1 = models.Charfield()
attr2 = models.Charfield(unique=True)
class ModelB(models.Model):
foreign = models.ForeignKey(ModelA)
class OtherFieldUniqueSerializer(serializers.PrimaryKeyRelatedField):
@arthuralvim
arthuralvim / pre-commit
Created Feb 4, 2015
Git pre-commit hook to check if there's any debugger breakpoint inside your python files.
View pre-commit
#!/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"
@arthuralvim
arthuralvim / enc_example.py
Last active Aug 29, 2015
Encryption example.
View enc_example.py
# -*- coding: utf-8 -*-
from Crypto.Cipher import XOR
import base64
import functools
import hashlib
def func_encrypt(key, plaintext):
cipher = XOR.new(key)
@arthuralvim
arthuralvim / testing_postgres_conn.py
Created Feb 24, 2015
Testing Postgres Connection
View testing_postgres_conn.py
#!/usr/bin/python
import psycopg2
import sys
host = ''
dbname = ''
user = ''
password = ''
port = 5432
@arthuralvim
arthuralvim / goc-2010.py
Created Mar 14, 2015
Google Developer Day 2010: Na pacata vila campestre de Ponteironuloville, todos os telefones têm 6 dígitos. A companhia telefônica estabelece as seguintes regras sobre os números: Não pode haver dois dígitos consecutivos idênticos, porque isso é chato; A soma dos dígitos tem que ser par, porque isso é legal; O último dígito não pode ser igual ao…
View goc-2010.py
# -*- 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 = []